Hello, I am trying to remove a players name/frame from my custom player list when the player leaves but there name is not getting removed
SERVER SCRIPT______________________LOCAL SCRIPT
Hello, I am trying to remove a players name/frame from my custom player list when the player leaves but there name is not getting removed
SERVER SCRIPT______________________LOCAL SCRIPT
You didn’t provide any argument for “LevelValue” and “playerName”.
Under the plagerremoving func, u didnt provide parameters.
I don’t think I need any, cause I don’t need to send anything right?
I dont think i need to send those over to the local script again
U do, since ur function takes in 2 args and if they rnt present u will get an error.
ok i did that But when i do 2 players then make one leave, the player that left, there name is still on the playerlist
Make a different remote for tht or just add another arg named state and when u fire it from the playerRemoving func send remove
as the state and vice versa. Coming to the remote func check wt state is, and based on it, do different stuff.
hmm, ok I’m going to try that tomorrow, I gtg
“string expected got nil”. The problem is that you never added any arguments into FireAllClients, like @DesertusX said. It’s clear as day in the screenshot you provided.
Ok yeah I did that but I still can’t get the players name/frame to remove when they leave
I’m still in need of help, the players name/frame is not getting removed when they leave
Can you at least copy and paste the code instead of screenshots so it’s easier to edit on our end?
UpdateList doesn’t add / remove a player, it goes through all players and creates a new frame for every player. Only giving a single LevelValue parameter also has the downside of every player seemingly having the same level.
One way to solve this, is by passing a boolean as parameter, stating whether the player joined or left. If joined, you will add a new PlayerFrame for only that player, and if left, you’ll search for his PlayerFrame and remove that.
I also don’t see why you don’t just use Players.PlayerAdded / Players.PlayerRemoving on the client. The values with playerdata are replicated to the client anyways, meaning you could simply do something like this:
-- client
Players.PlayerAdded:Connect(function(Player)
local NewPlayerFrame = PlayerFrame:Clone()
NewPlayerFrame.Name = Player.Name
NewPlayerFrame.Levellabel.Text = Player:WaitForChild("LevelValue").Value
NewPlayerFrame.NameLabel.Text = Player:WaitForChild("CashValue").Value
NewPlayerFrame.Parent = script.Parent
end)
Players.PlayerRemoved:Connect(function(Player)
if script.Parent:FindFirstChild(Player.Name) then
script.Parent[Player.Name]:Destroy()
end
end)
You’ll also have to look out for any players having the same name as your script, because they can destroy the script, but that’s not the hardest thing to look out for.
Lol I know, I made the scripts myself but anyway I didn’t know that the players are gonna have the same lvl, I never tested it yet and also player.playeradded doesn’t work on client
Just tested it myself, and Players.PlayerAdded does work on the client. You only need to be careful that Players.PlayerAdded does not get called for existing players. Connecting Players.PlayerAdded to the function, and then looping through all existing players and calling the function should fix this issue.
wait but I did Player.PlayerAdded on client and tried to print the player that joined and it didn’t work
nothing prints
Those two functions work on client just for other users, If you join it won’t fire PlayerAdded for you since you are the client that joined but for other people in the game it’ll fire the RBXSignal.
ohhhh ok , I just tested it with 2 people and I see that it works