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

How do I show a Humanoids speed on Leaderboards?

Asked by 4 years ago
Edited 4 years ago

When I was typing I thought it was completely simple, but when I looked at it as I got the error I just couldn't figure out. I just thought I would put Speed.Value as game.Players.LocalPlayers.Character.Humanoid.WalkSpeed. Any way this is what I had.

game.Players.PlayerAdded:Connect(function(player)


    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local plr = game.Players.LocalPlayer.Character.Humanoid
    local speed = Instance.new("NumberValue")
    speed.Name = "Speed"
    speed.Parent = leaderstats
    speed.Value =  plr.WalkSpeed



end)

3 answers

Log in to vote
0
Answered by 4 years ago

Instead of checking for the walkspeed in the player you want to check the humanoids walkspeed. Use player.Character.Humanoid.WalkSpeed to start it off then in another script that you put inside the players character (By placing it in game.StarterPlayer.StarterCharacterScripts) with this code:

while wait() do
    local Char = script.Parent
    local Humanoid = Char:WaitForChild("Humanoid")
    local player = game.Players:GetPlayerFromCharacter(Char)

    if player then --Just to make sure
        local stats = player:WaitForChild("leaderstats")
        local speed = stats:WaitForChild("Speed")
        speed.Value = Humanoid.WalkSpeed
    end
end

Remember to put that in a server script not a local script

0
What are you saying I should do with the player.Character.Humanoid.WalkSpeed? Benny267 0 — 4y
0
I would recommend using :GetPropertyChangelSignal() to do this. Lucke0051 165 — 4y
0
And don't you need to express humanoid by doing game.Player etc. Benny267 0 — 4y
0
Not if you already have the player expressed MrCatDoggo 213 — 4y
View all comments (5 more)
0
in your leaderboard use the player.Character.Humanoid.WalkSpeed to set it by default MrCatDoggo 213 — 4y
0
Where would I put player.Character.Humanoid.WalkSpeed Benny267 0 — 4y
0
nvm Benny267 0 — 4y
0
Its saying Humanoid is a (nil value) Benny267 0 — 4y
0
infact have the leaderstat script set it to 16 be default MrCatDoggo 213 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Could you do... (LeaderStats is your script)

speed.Value = game:FindFirstChild("LeaderStats")
0
Nope MrCatDoggo 213 — 4y
Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
4 years ago
Edited 4 years ago

Well in this case follow these steps.

1) Make sure that your leaderstats script only has the variables such as speed. As I see up there you have used LocalPlayer which wont work in normal scripts.

2) Just delete those and make a normal leaderstats script with speed or the things you want.

3) Insert a local script in starter player > starter character scripts.

4) In that local script type in the following.

while wait(1) do
    local plr = game.Players.LocalPlayer
    local speed = plr.leaderstats.Speed
    speed.Value = script.Parent:FindFirstChild("Humanoid").WalkSpeed
end

OR if you want to make the opposite. (Leaderstats = character speed) then follow this code


while wait(1) do local plr = game.Players.LocalPlayer local speed = plr.leaderstats.Speed script.Parent:FindFirstChild("Humanoid").WalkSpeed = speed.Value end

Answer this question