#Door
24 messages · Page 1 of 1 (latest)
I think i found a method using a hidden part as the player detector and a table to store players inside of that hitbox part
a lazy way would be to just check it via coordinates. e.g. here you see that if the coord is smaller than it's on the left, else i'ts on the right. Use some simple algebra to do this for doors on an angle. You will only have to do it on a 2d plane
The right way would be to just use some zoning logic to determine the zone the player is currently in
i made it so if the player is close enough to a side of the door it adds them to a table for that side
but Im trying to figure out how to not make it delete everyone in the table as soon as the player leaves
Why would it delete everyone from the table?
if hit.Parent:FindFirstChild("Humanoid") and not table.find(playerInTheBackSide, hit.Parent)then
table.insert(playerInTheBackSide,hit.Parent)
end
print(playerInTheBackSide)
end)
backside.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
table.remove(playerInTheBackSide, table.find(playerInTheBackSide, hit.Parent))
end
print(playerInTheBackSide)
end)```
prints a empty table if there's 2 players inside of the part.touched and one of them stops touching
My main guess is that a debounce should solve it. But that could still get some odd behaviors
im gonna try swapping hit.parent by players:getplayerfromcharacter and see if that works
yep that works
it deleted every humanoid touching it before
That's also an option yeah. But still add in the db nonetheless. My main guess is that the function gets called twice, it finds (e.g.) entree 1 twice, so it removes entree 1, resorts, removes entree 1 again
They're really useful for when you don't want a piece of code to run way too often
e.g. .Touched can fire a few hundred times within a second (or some other arbitrary number, larger than the optimal "1") . In that case just use a debounce to only take 1 inout per a frame or something similar
table.insert(playerInTheBackSide,players:GetPlayerFromCharacter(hit.Parent))
end
backdeb = false
task.wait(0.1)
backdeb =true
end)``` debounce works like this right?
if hit.Parent:FindFirstChild("Humanoid") and not table.find(playerInTheBackSide, hit.Parent) and backdeb then
backdeb = false
table.insert(playerInTheBackSide,players:GetPlayerFromCharacter(hit.Parent))
task.wait(0.1)
backdeb =true
end