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

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

Asked by
caipira 29
6 years ago

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
0
Localscript or serverscript? MachoPiggies 526 — 6y
0
local caipira 29 — 6y
0
You can't use local scripts on ClickDetectors, you must use a server script and get the player that clicked it. Mr_MilkysButler 47 — 6y
0
sorry it's a serverscript :p caipira 29 — 6y

1 answer

Log in to vote
0
Answered by
xEiffel 280 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
it work, and i understand now, thanks caipira 29 — 6y
0
Alright cool. xEiffel 280 — 6y
Ad

Answer this question