I get this error, Workspace.BootShack.Boots.Clickbox.ClickDetector.BuyBoot:17: attempt to index nil with 'Name'
Code is right here.
01 | local player = game.Players.LocalPlayer -- this is the variable im referencing. |
02 |
03 |
04 | script.Parent.MouseClick:Connect( function () |
05 |
06 | if _G.points < 3 then |
07 |
08 | print ( "Player is missing required money." ) |
09 |
10 | end |
11 |
12 | if _G.points > 2 then |
13 |
14 | _G.points = _G.points - 3 |
15 | workspace { player.Name } :FindFirstChild( "Humanoid" ).WalkSpeed = 22 --I get the error right here. |
if its a localscript just use localplayer
1 | if _G.points > 2 then |
2 | _G.points = _G.points - 3 |
3 | game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 22 |
4 | script.Parent.MaxActivationDistance = 0 |
5 | script.Parent.Parent.Parent.Boots.Transparency = 1 |
6 | script.Parent.Parent.Parent.Boots.CanCollide = false |
7 | end |
I'm sorry, but local scripts can't work on the workspace. Local scripts only work if it is a descendant of the local player or the local player's character. Instead, replace the local script with a server script (normal script) with the following code:
01 | script.Parent.MouseClick:Connect( function (playerWhoClicked) --calls a function when clickdetector is clicked |
02 | if _G.points < 3 then return end -- if player doesn't have enough money the script says screw it don't run this function |
03 | if _G.points > 2 then -- everything else after this line is the same as your script. |
04 | _G.points = _G.points - 3 |
05 | local playerName = playerWhoClicked.Name |
06 | local chr = game.Workspace:FindFirstChild( "" ..playerName) |
07 | chr.Humanoid.Walkspeed = 22 |
08 | script.Parent.MaxActivationDistance = 0 |
09 | script.Parent.Parent.Parent.Boots.Transparency = 1 |
10 | script.Parent.Parent.Parent.Boots.CanCollide = false |
11 | end |
12 | end ) |
It should work now however if it doesn't work, let me know. I would use GetCharacterFromPlayer instead of FindFirstChild(""..playername) but sadly GetCharacterFromPlayer is not a thing in roblox scripting yet.