Search code examples
luaroblox

attempt to index nil with 'LocalPlayer'


so basically i was making a power up script until its error showed up: Workspace.Part.Script:5: attempt to index nil with 'LocalPlayer'. Also im new to all of this so i dont really have the best clue on why this happened.

heres the script:

`

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.MaxHealth = math.huge 
        hit.Parent.Humanoid.Health = math.huge 
        Players.LocalPlayer.Character.Humanoid.WalkSpeed = 36
        Players.LocalPlayer.Character.Humanoid.JumpPower = 10
    end
end)



`

To be honest not much. I tweaked some grammar and stuff nothing helped though.

type here

Solution

  • script.Parent.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            hit.Parent.Humanoid.MaxHealth = math.huge 
            hit.Parent.Humanoid.Health = math.huge 
            hit.Parent.Humanoid.WalkSpeed = 36
            hit.Parent.Humanoid.JumpPower = 10
        end
    end)