✓ Accepted answer
Well for starters, there are a few problems in your script that can easily be fixed(Luckily I'm here to help you do it :D).
#Problem #1(and #2 kinda)
For starters, you're editing a GUI on the Server Side when you should be doing it on the Client Side(especially if you're using Filtering Enabled[soon to be called Non-experimental mode]).
To fix this, instead of having the client ask the server to update the list, you should do the opposite, which would look a little bit like this:
game:GetService("Players").PlayerRemoving:Connect(function(Player)
print(player.Name.." is leaving the server.")
for _,p in pairs(game:GetService("Players"):GetPlayers()) do
if p ~= Player then
script.Go:InvokeClient(p.Name)
end
end)
end)
Now we have the server calling the shots instead of the client, however the client what to do! Which is why we have to tell it by adding a callback to the RemoteFunction, which would look a little bit like this:
workspace.Leave.Go.OnClientInvoke = function(whoLeft)
for _,l in pairs(workspace.Leaderboard.SurfaceGui.Frame:GetChildren()) do
if l.Name == whoLeft then
print("This dude left! Mollywopping his name off my list.")
l:Destroy()
end
end
end
The confused client knows what it's doing, and evolves into the smart client! Now when the player leaves, the client does all the work(which it's supposed to when it comes to gui work), and the server just acts as the messenger! Neat, right?
#Notes
- Instead of having your RemoteFunctions/RemoteEvents inside of the server script, move them to
ReplicatedStorage for easier access.
- Do note: When doing GUI work, all work should be done on the client instead of the server, ESPECIALLY when using FE.
- I wrote this at 1 in the morning, so sorry if I sound a bit loopy.
- All code was written in the website answer box, so if I made a mistake, please tell me and I will fix it immediately.
1 comment
You never passed the player as an argument in the local script.