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

Workspace.botaozim.Script:4: attempt to index local 'player' (a nil value)??

I'm trying to make a button that sets the the player's WalkSpeed to 150, what's wrong?

local button = script.Parent

local player = game.Players.LocalPlayer --Find Player name
local nameofplayer = player.Character.Name--Get the player in workspace


botaoz.ClickDetector.MouseClick:connect(function(player)
	Workspace.Player.Name.Humanoid.WalkSpeed = 150
end

4 comments

0

Localscript or serverscript?

0

local

0

You can't use local scripts on ClickDetectors, you must use a server script and get the player that clicked it.

0

sorry it's a serverscript :p

1 answer

✓ Accepted answer

You haven't given any time for the players character to load, also, you didn't put square brackets around the workspace modifier part, and 'Workspace' is deprecated, use 'workspace' instead. Here is the modified script -

local button = script.Parent

game.Players.PlayerAdded:Connect(function(player) -- wait for the player to be added
player.CharacterAdded:Connect(function(character) -- wait for the character to be added
local nameofplayer = player.Name -- get the player in workspace


botaoz.ClickDetector.MouseClick:connect(function(player)
    workspace[nameofplayer].Humanoid.WalkSpeed = 150 --[[ Use the square brackets for referencing--]]
end)
end)
end)

2 comments

0

it work, and i understand now, thanks

0

Alright cool.

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