I’m trying to make a round UI similar to the one in Piggy where once you click a button, it shows all other players who’ve clicked the button and joined the round. Currently there is no round system in place. Just the joining system.
My problem is when a player leaves, it doesn’t remove a cloned template that has their name on it. The error being “PlayerGui is not a valid member of [PLAYER]” This is in a local script so it’s able to show the round to everyone. I’m using a list to keep track of the players who’ve clicked the button and get their usernames so I can find the PlayerGui. I’m not sure why this is happening as server side does have access to PlayerGui.
I’ve tried changing the scripts a bit, but I’m not too sure if it has anything to do with calling “In pairs” twice in one script, or if it’s something to do with me calling the player “v”. The script is below, and the function “heheheyup” activates once a player clicks on the button to get into a round. I took some of this from roblox’s page for remote events, so some defined things may be different than what they say they are.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Events").round
local playing = {}
local Players = game:GetService("Players")
-- Create a new part
local function heheheyup(player)
print(player.Name .. " fired the remote event")
local Button = player.PlayerGui.round.Frame.clonetemplate
local ScrollingFrame = player.PlayerGui.round.Frame
local plrname = player.Name
table.insert(playing,plrname)
print(playing)
local string1 = Instance.new("StringValue")
string1.Value = plrname
string1.Name = plrname
string1.Parent = game.Players:WaitForChild("Clickedplay")
local CloneButton = Button:Clone()
CloneButton.Name = plrname
CloneButton.Text = plrname
CloneButton.Parent = ScrollingFrame
CloneButton.Visible = true
end
local function playedadded(plr)
for i,v in pairs(playing) do
print(v)
print(plr)
local wowplay = v
-- if plr:FindFirstChild("PlayerGui"):WaitForChild("round") then
-- print("ok...")
--end
local Button = game.Players:FindFirstChild(plr.Name).PlayerGui:WaitForChild("round").Frame.clonetemplate
local ScrollingFrame = game.Players:FindFirstChild(plr.Name).PlayerGui:WaitForChild("round").Frame
local plrname = v
local CloneButton = Button:Clone()
CloneButton.Name = v
CloneButton.Text = v
CloneButton.Parent = ScrollingFrame
CloneButton.Visible = true
end
end
local function PlayerLeft(plr)
for i, v in pairs(game.Players.Clickedplay:GetChildren()) do -- all players
if v.Name == plr.Name then
game.Players.Clickedplay:FindFirstChild(plr.Name):Destroy()
end
print(v)
for i, v in pairs(game.Players:FindFirstChild(v.Name).PlayerGui.round.Frame:GetChildren()) do
local name = v.Name
game.Players.Name.PlayerGui.round.Frame:FindFirstChild(plr.Name):Destroy()
if v.Name == plr.Name then
print("ok")
local plrname = plr.Name
table.remove(playing, plrname)
end
end
end
end
-- Call "onCreatePart()" when the client fires the remote event
remoteEvent.OnServerEvent:Connect(heheheyup)
Players.PlayerAdded:Connect(playedadded)
Players.PlayerRemoving:Connect(PlayerLeft)
If theres anything I can do to fix this, or if anyone needs more information about this please let me know.


