Basically, I am trying to make a player list surface gui and it’s all great and working, yet it won’t destroy the player’s name on the player list when they leave.
game.Players.PlayerRemoving:Connect(function(Player)
local plr = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
local cal = plr:FindFirstChild(Player.Name)
cal:Destroy()
end)
All I get is an error message in output saying Attempt to index nil with ‘Destroy’. Does anyone have any idea what is going on with this?
Edit: Here is the full script that has been edited, hopefully this provides more to go off of:
game.Players.PlayerAdded:Connect(function(Player)
local Name = Player.Name
if Name then
local GUI = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame.Player1:Clone()
GUI.Parent = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
GUI.TextButton.Text = Name
GUI.Name = Name
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local plr = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
local cal = plr:FindFirstChild(Player.Name)
if cal then
cal:Destroy();
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if Player then
local plr = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
local cal = plr:FindFirstChild(Player.Name)
cal:Destroy()
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local plr = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
local cal = plr:FindFirstChild(Player.Name)
if cal ~= nil then cal:Destroy() end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ScrollingFrame = workspace.Laptop.Screen.SurfaceGui.ImageLabel.StartScreen2.ScrollingFrame
for i,v in pairs(ScrollingFrame:GetChildren()) do
if v.PlayerName.Text == Player.Name then
v:Destroy()
end
end
end)
You could use something like this to check for the player’s name in the list
The error you get means that the object you’re referring to and want to destroy doesn’t exist. Make sure cal is an object. You can’t destroy something that doesn’t exist.
I’d assume so. I’ve been testing in-game and it still hasn’t deleted the player’s name from the list. I’m thinking the game might not have updated yet so I’m going to use your script and try again in 5 minutes or so.
But why are you testing in-game?
You can also test in studio and the results will be the same.
(There are some exceptions of course but it will work with your issue)
You should always test in studio to save time.
For example, Roblox declines publish request if you send a lot of them or you changed literally nothing inside your game.
Ok. I was testing in game because I was confused on how the simulated player test system works in studio. Can I add and remove players in test? How would I do this? This would save a lot of time I just can’t find how to do it.
What do you mean “add and remove players in test”?
There’s an option to test your game with multiple Roblox Studio windows.
Test > Clients and Servers
From there, you can pick how many ‘players’ do you want to test your game with. (These ‘players’ will be your dummies which you can control just like a normal player)
I wouldn’t recommend setting this above 4, because your PC might crash or lag. So be careful.