I get this error, Workspace.BootShack.Boots.Clickbox.ClickDetector.BuyBoot:17: attempt to index nil with 'Name'
Code is right here.
local player = game.Players.LocalPlayer -- this is the variable im referencing. script.Parent.MouseClick:Connect(function() if _G.points < 3 then print("Player is missing required money.") end if _G.points > 2 then _G.points = _G.points - 3 workspace{player.Name}:FindFirstChild("Humanoid").WalkSpeed = 22 --I get the error right here. script.Parent.MaxActivationDistance = 0 script.Parent.Parent.Parent.Boots.Transparency = 1 script.Parent.Parent.Parent.Boots.CanCollide = false end end)
if its a localscript just use localplayer
if _G.points > 2 then _G.points = _G.points - 3 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed =22 script.Parent.MaxActivationDistance = 0 script.Parent.Parent.Parent.Boots.Transparency = 1 script.Parent.Parent.Parent.Boots.CanCollide = false 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:
script.Parent.MouseClick:Connect(function(playerWhoClicked) --calls a function when clickdetector is clicked if _G.points < 3 then return end -- if player doesn't have enough money the script says screw it don't run this function if _G.points > 2 then -- everything else after this line is the same as your script. _G.points = _G.points - 3 local playerName = playerWhoClicked.Name local chr = game.Workspace:FindFirstChild(""..playerName) chr.Humanoid.Walkspeed = 22 script.Parent.MaxActivationDistance = 0 script.Parent.Parent.Parent.Boots.Transparency = 1 script.Parent.Parent.Parent.Boots.CanCollide = false end 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.