I attempted to make a part that only one player can touch and be added to a table, and when he untouches the part he gets removed from that table.
But my code didn't work and I don't know the reason
Here's my attempt:
local team1 = script.Parent.Team1
local maximum_1 = false
local team_table_1 = {}
local function onTouch(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player then return end
if not maximum_1 then
maximum_1 = true
while true do
wait(hit)
table.insert(team_table_1, player.Name)
print'added'
end
end
end
local function onTouchEnded()
table.remove(team_table_1, 1)
print'removed'
end
team1.Part1.Touched:Connect(onTouch)
team1.Part1.TouchEnded:Connect(onTouchEnded)

2 comments
Sorry but I don't understand, what should I do exactly? Can you explain and give an example in a sample of code?
Don't remove the table. Just set it to a new parent outside of the global scene. Table isnt a element. It is a method so you can store it as a variable which we call values. You can make a stringvalue then parent the string value to the replicated storage.