Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

help plz

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

2 comments

0

To use LocalPlayer. You have to use a local script:=)

0

i did and it didnt do anything

2 answers

✓ Accepted answer

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

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!

2 comments

0

doent work\

1

The purpose is not to directly give you a script but to learn from it.

This discussion is preserved as it was. New answers, comments, and votes are closed.