Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

13:11:34.004 - Workspace.Part.Script:2: attempt to index field 'LocalPlayer' (a nil value) help?

Asked by 4 years ago

help plz

script.Parent.Touched:Connect(function()
 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 64
end)

0
To use LocalPlayer. You have to use a local script:=) Skydoeskey 108 — 4y
0
i did and it didnt do anything Vortex_Vasne 89 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

Your code should work as long as you use a local script, but you can try to find the character a different way.

Your code:

script.Parent.Touched:Connect(function()
 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 64
end)

You could also change :Connect(function() to :Connect(function(character) (allowing you to establish who the character is easier):

script.Parent.Touched:Connect(function(character)
 character.Humanoid.WalkSpeed = 64
end)

If all else fails check out these links:

LocalScripts

LocalPlayer

Script

Detecting collisions

WalkSpeed

Ad
Log in to vote
0
Answered by 4 years ago

game:GetService("Players").LocalPlayer only works for LocalScripts, BUT, you can get the player through Character (which you don't actually need in this case because you're editing a property of the Humanoid which is in the character):

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
        Hit.Parent.Humanoid.WalkSpeed = 64
    end
end)

IF you want a players only then:

script.Parent.Touched:Connect(function(Hit)
    if Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
        local IsPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent)
        if IsPlayer then
            Hit.Parent.Humanoid.WalkSpeed = 64
        end
    end
end)

Good luck!

0
doent work\ Vortex_Vasne 89 — 4y
1
The purpose is not to directly give you a script but to learn from it. BlackOrange3343 2676 — 4y

Answer this question