Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The leaderboard is working for 1 player only, why?

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 !

2 comments

0

PlayerAdded passes one player argument at a time.

0

What can I do instead of PlayerAdded? @MCAndRobloxUnited

1 answer

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?

3 comments

0

I mean, you're supposed to handle the leaderstats with LocalScripts.

0

Ok thanks but I'm not that good at scripting can you please, tell me how to do that ^^

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.