Hello, I’ve been working on a waiting out button for a round based game, however I’m having issues with the tables, this is my current script for reading when the person pressed the button:
script.Parent.MouseButton1Click:Connect(function(PLRpressed)
if script.Parent.Text == “Waiting for a game” then
script.Parent.Text = "Waiting out"
game.ReplicatedStorage.WaitingOut:FireServer(PLRpressed)
else
script.Parent.Text = "Waiting for a game"
game.ReplicatedStorage.WaitingForAGame:FireServer(PLRpressed)
end
end)
This is where the server picks up on the button press:
game.ReplicatedStorage.WaitingOut.OnServerEvent:Connect(function(Player,PLRpressed) try replacing the respective line with this, your first parameter is actually the player not what you send
oh okay i see, you should remove the stuff based on indexes. try doing this,
local numb=0
for i,v in next, PLRwaitingList do
numb=numb+1
if v==WaitingOutButtonPress then
break
end
end
table.remove(PLRwaitingList,numb)
i haven’t tested the code, but maybe this gives you the idea, right? you need to include where the object is in the array and then put that number inside of the table.remove()
it’s because the table.remove() only accepts the table AND the position of your object. it does not accept objects themselves sadly. you need to find where it’s at the table and then include that there. so like table.remove(Table,PositionNumber) should be what you should use and it’ll work.
okay im assuming that WaitingOutButtonPress if the item you’re trying to remove, right? if so, then you would go through your table and find where it is and then store the position number and then after that call table.remove(YourTable,PositionNumber), go look through the code i provided for the idea
I see, but this is the rest of my code I just want to make sure it would still run.
–Game Stats
local roundLength = 60 --Change this value to edit the ingame length
local preroundLength = 15 --Change this value to edit the preround length
local InRound = game.ReplicatedStorage:WaitForChild(“InRound”)
local Lobbyspawn = game.Workspace.LobbySpawn
local GameSpawn = game.Workspace.GameSpawn
local Status = game.ReplicatedStorage:WaitForChild(“Status”)
local PLRwaitingList = {}
InRound.Changed:Connect(function()
if InRound.Value == true then
local UpperTilesClone = game.ReplicatedStorage.UpperTiles:Clone()
UpperTilesClone.Parent = game.Workspace
UpperTilesClone.Name = "UpperTiles"
local BottomTilesClone = game.ReplicatedStorage.BottomTiles:Clone()
BottomTilesClone.Parent = game.Workspace
BottomTilesClone.Name = "BottomTiles"
game.Workspace.Bell.Playing = true
wait(1)
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = GameSpawn.CFrame
game.Workspace.ThemeMusic:Play()
end
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = Lobbyspawn.CFrame
wait(1)
game.Workspace.UpperTiles:Destroy()
game.Workspace.BottomTiles:Destroy()
end
end
end)
local function roundTimer()
while wait() do
for i = preroundLength, 1, -1 do
local Click = game.Workspace.TimerClick
Click:Play()
InRound.Value = false
wait(1)
Status.Value = “Preround: “… i …” seconds left!”
end
for i = roundLength, 1, -1 do
InRound.Value = true
wait(1)
Status.Value = “Game: “… i …” seconds left!”
end
end
end
spawn(roundTimer)
game.ReplicatedStorage.WaitingOut.OnServerEvent:Connect(function(PLRpressed)
local WaitingOutButtonPress = PLRpressed
print(WaitingOutButtonPress)
table.remove(PLRwaitingList, WaitingOutButtonPress)
print(“WORKED”)
end)
game.ReplicatedStorage.WaitingForAGame.OnServerEvent:Connect(function(PLRpressed)
local AwaitingGameButtonPress = PLRpressed
print(AwaitingGameButtonPress)
table.insert(PLRwaitingList, AwaitingGameButtonPress)
print(“Worked”)
print(PLRwaitingList)
local PlayerIndex = table.find(PLRwaitingList, PLRpressed) -- get the index of the player in the table
if PlayerIndex then
table.remove(PLRwaitingList, PlayerIndex) -- remove element at the index
end