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

Player Walkspeed = Leaderstat Script Not Working?

Asked by 6 years ago

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)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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.

0
It should be plr.Character not player.Character MiracleDev 15 — 6y
0
Just saw that User#20388 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question