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

The leaderboard is working for 1 player only, why?

Asked by 5 years ago

I have made a script that display the height (Y Position of the player's torso) but it's only working for 1 player and I don't understand why

Here is the script :

local function OnPlayerJoin(player)
    repeat wait() until player.Character

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

    local Height = Instance.new("IntValue")    
    Height.Name = "Height"    
    Height.Parent = leaderstats

        while true do

            for i, player in pairs(game.Players:GetPlayers()) do    
            local char = player.Character    
            if char:FindFirstChild("HumanoidRootPart") then    
            Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8)    
                end
            end
        wait()  
    end    
end

game.Players.PlayerAdded:Connect(OnPlayerJoin)

The script is in ServerScriptService and it's a normal script

Thank you in advance !

0
PlayerAdded passes one player argument at a time. DeceptiveCaster 3761 — 5y
0
What can I do instead of PlayerAdded? @MCAndRobloxUnited Louix27626 83 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I have experimented a bit and I figured out that when I'm playing it display my height until I fall in the void, at this moment my height is the height of another player in the game (and his value is 0).

It's probably an issue with the part of the script where it search for HumanoidRootPart, the script take only the first value he can find. I don't know how to fix that. Maybe with a LocalScript?

0
I mean, you're supposed to handle the leaderstats with LocalScripts. DeceptiveCaster 3761 — 5y
0
Ok thanks but I'm not that good at scripting can you please, tell me how to do that ^^ Louix27626 83 — 5y
0
Fire the client of the player with a RemoteEvent when they're added to a LocalScript, then it can create leaderstats for the specific player. Joshument 110 — 5y
Ad

Answer this question