I have made a game where you need to climb, I wanted to add a leaderboard who show the height of each players in the game, so I made a script with tutorials (I'm not very good :P) it works for one player but not for everyone. I have already asked a question about this but it didn't help me or almost : I learnt that i needed to use RemoteEvent but i can't find how to make my leaderboard work!
Here is the scripts :
It's a Regular Script in ServerScriptService :
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 game.ReplicatedStorage.RemoteEvent1:FireClient(player) end game.Players.PlayerAdded:Connect(OnPlayerJoin)
And this is a LocalScript in StarterGui :
local function HeightCalc(player) repeat wait() until player.Character while true do for i, player in pairs(game.Players:GetPlayers()) do local char = player.Character if char:FindFirstChild("HumanoidRootPart") then local Height = player.leaderstats.Height Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8) end end end end game.ReplicatedStorage.RemoteEvent1.OnClientEvent:Connect(HeightCalc)
Thank you in advance!
inside ur server script, at the end beore u stop the script type the following
game:GetSerice("ReplicatedStorage"):WaitForChild("RemoteEvent").OnServerevent:Connect(function() Height.Value = Height.Value + the value you want here end)
and in ur local script u cant change the leaderstats, that can only be done by a local script, instead change
local Height = player.leaderstats.Height Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8)
into game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireServer()
I modified my scripts with your tips but now, the height value is 0 and it is not changing anymore it's probably my fault but i cant spot my mistake(s)
Normal Script in ServerScriptService :
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 game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent1").OnServerEvent:Connect(function() Height.Value = (player.Character.HumanoidRootPart.Position.Y - 8) end) end game.Players.PlayerAdded:Connect(OnPlayerJoin)
LocalScript in StarterGui :
local function HeightCalc(player) repeat wait() until player.Character while true do for i, player in pairs(game.Players:GetPlayers()) do local char = player.Character if char:FindFirstChild("HumanoidRootPart") then game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireServer() end end end end game.ReplicatedStorage.RemoteEvent1.OnClientEvent:Connect(HeightCalc)