(I made a custom leaderboard)
I have created a remote event that runs everytime a player leaves or joins the game. I added a script which adds the player to the leaderboard, but the code won't run. No errors come into the console either.
Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoveRemoteEvent = ReplicatedStorage:WaitForChild("LeaderboardRemovePlayer") local AddRemoteEvent = ReplicatedStorage:WaitForChild("LeaderboardAddPlayer") game.Players.PlayerAdded:Connect(function() AddRemoteEvent:FireServer() end) game.Players.PlayerRemoving:Connect(function() RemoveRemoteEvent:FireServer() end)
Server Script
local ServerStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") local Teams = game:GetService("Teams") local RE = game:GetService("ReplicatedStorage"):WaitForChild('LeaderboardAddPlayer') RE.OnServerEvent:Connect(function() for i,v in pairs(Players:GetPlayers()) do ServerStorage:WaitForChild("PlayerThing").Parent = v.PlayerGui:WaitForChild("Leaderboard"):WaitForChild("PlayerList") end RE:FireAllClients() end)
Instead of running the PlayerAdded
code on your client (which would call the server several times if you have more than one player), why not do it in the server?
local ServerStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") local Teams = game:GetService("Teams") local RE = game:GetService("ReplicatedStorage"):WaitForChild('LeaderboardAddPlayer') local function onPlayerAdded() for i,v in pairs(Players:GetPlayers()) do ServerStorage:WaitForChild("PlayerThing").Parent = v.PlayerGui:WaitForChild("Leaderboard"):WaitForChild("PlayerList") end RE:FireAllClients() end local function onPlayerDisconnect() -- do something when the player disconnects end Players.PlayerAdded:Connect(onPlayerAdded) Players.PlayerRemoving:Connect(onPlayerDisconnect)