Hey! I have a door that teleports players but I want it to function so when a said amount of players are on a part, it’ll close this door by enabling an invisible wall.
This is how I have it scripted so far:
function touch(hit)
local players = game.Players:GetChildren()
if #players >= 1 then
game.Workspace.BARRIERA.CanCollide = true
end
local players = game.Players:GetChildren()
if #players >- 0 then
game.Workspace.BARRIERA.CanCollide = false
end
end
script.Parent.Touched:connect(touch)
And the part is located in workspace that needs the collisions changed and named “BARRIERA”
No errors are being printed at all, any help is very appreciated!
function touch(hit)
local players = game.Players:GetChildren()
if #players > 1 then
game.Workspace.BARRIERA.CanCollide = true
end
local players = game.Players:GetChildren()
if #players < 0 then
game.Workspace.BARRIERA.CanCollide = false
end
end
script.Parent.Touched:connect(touch)
I think you may be right? I think this is correct, but then when joining it’ll lock the door even if nobody is standing on the point
Uh you are just getting a list of players in the Players, not the ones touching the door.
This should work:
function touch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
if humanoid > 0 then
game.Workspace.BARRIERA.CanCollide = true
end
else
game.Workspace.BARRIERA.CanCollide = true
end
script.Parent.Touched:connect(touch)
No errors, and it should work so if two players are standing on a part let’s say, the door will lock. If they leave (or get teleported off in this instance) it’ll open again to allow another 2 players in but I believe @NeoGaming_RBLX may have found the solution.
Thanks! Just tried, no errors but still not functioning
function touch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
if humanoid > 0 then
game.Workspace.BARRIERA.CanCollide = true
print("Test")
end
else
game.Workspace.BARRIERA.CanCollide = true
end
script.Parent.Touched:connect(touch)
end
OH I THINK I FOUND IT dont use >0 because even if just one player is on it then it blocks the player (can collide true)
use > 1 or > 2
also you set both can collide statements to true so in any way it would always be true