So, I have a game I am making. I want to make the players walkspeed = the value of a certain leaderstat (snow). This is the script I tried, if you know why it isn't working, please tell me.
plr = script.Parent.Parent.Parent.Parent.Parent local speed = plr.leaderstats.Snow.Value function onPlayerEntered(newPlayer) newPlayer.Character.Humanoid.WalkSpeed = speed end game.Players.ChildAdded:connect(onPlayerEntered) function onPlayerRespawned(newPlayer) h = newPlayer:findFirstChild("Humanoid") if h ~= nil then if game.Workspace:findFirstChild(h.Parent.Name) ~= nil then h.WalkSpeed = speed end end end game.Workspace.ChildAdded:connect(onPlayerRespawned)
local plr = game.Players.LocalPlayer -- Notice, this needs to be a local script inside starterpack while wait() do local char = plr.Character if char then local hum = char:WaitForChild("Humanoid") hum.WalkSpeed = plr:WaitForChild("leaderstats"):WaitForChild("Snow").Value end end
Please tell me if I made any typing mistakes.
Hello, Welovegod. I made it a local script and changed a bit of code and I got it to work. Here is the script I used:
local plr = game.Players.LocalPlayer function GiveSpeed() game.Players.LocalPlayer:WaitForChild("leaderstats")--If you are using a script for leaderstats snow = game.Players.LocalPlayer.leaderstats.Snow while true do wait(0.1) game.Workspace[plr.Name].Humanoid.WalkSpeed = snow.Value end end GiveSpeed() function onPlayerRespawned(newPlayer) local h = newPlayer:findFirstChild("Humanoid") if h ~= nil then if game.Workspace:findFirstChild(h.Parent.Name) ~= nil then h.WalkSpeed = snow end end end game.Workspace.ChildAdded:connect(onPlayerRespawned)