I don’t really wanna dump the entirety of my code here since it’s a bit long, but in the basics:
On a part being touched, it’ll check if the player is in a certain table, if no; it’ll add the player to the table, then put them in a certain area.
Everything works fine there.
Now on a remote event; (specific one for that particular part) it will check if the request text was “leave” then remove the player from said table, then put them outside of the specific area. The issue with this, is that after around a second or so, the player gets put back inside the box with the same gui showing up that lets them leave, and they aren’t a part of the table at all, but they just get given the gui again and teleported inside.
Is there any reason why this would happen?
(specific code segment if needed; nothing substantial, PLEASE ignore the messy code, i have been modifying this code constantly in an attempt to try and fix it but nothing has been solving the issue.)
p.Touched:Connect(function(hit)
if #tableOfPlayers < maximumAllowed then
if players:GetPlayerFromCharacter(hit.Parent) then
print("touched")
local plr = players:GetPlayerFromCharacter(hit.Parent)
local chr = plr.Character
if not table.find(tableOfPlayers, plr) and not plr.PlayerGui:FindFirstChild("exitElevator") then
if allowCountdown == true then
startCountDown()
end
table.insert(tableOfPlayers, plr)
print("added")
chr.HumanoidRootPart.Position = p.Parent.Inside.Position
local clone = script.exitElevator:Clone()
clone.Parent = plr.PlayerGui
clone.r.Disabled = false
end
end
if players:GetPlayerFromCharacter(hit.Parent.Parent) then
print("touched")
local plr = players:GetPlayerFromCharacter(hit.Parent.Parent)
local chr = plr.Character
if not table.find(tableOfPlayers, plr) and not plr.PlayerGui:FindFirstChild("exitElevator") then
if allowCountdown == true then
startCountDown()
end
table.insert(tableOfPlayers, plr)
print("added")
chr.HumanoidRootPart.Position = p.Parent.Inside.Position
local clone = script.exitElevator:Clone()
clone.Parent = plr.PlayerGui
clone.r.Disabled = false
end
end
end
end)
script:FindFirstChild("fired").OnServerEvent:Connect(function(plr, request)
print(request)
if request == "leave" then
for i, v in ipairs(tableOfPlayers) do
if v == plr then
table.remove(tableOfPlayers)
end
end
plr.PlayerGui.exitElevator:Destroy()
plr.Character.HumanoidRootPart.Position = p.Parent.Outside.Position
end
end)
I don’t really want a workaround to using Touched all that much since I just want to know what’s causing it so I can avoid this in the future.
None of them really match to what I wanna do in my system; for more context.
This is in a box type situation; where when the player touches the wall, they get shoved inside, when the timer ends they get teleported to a game, and if they get out, they don’t get teleported. The only issue that I can find right now is that it could cause some confusion.