✓ Accepted answer
First: your syntax isn't right. You should tab your code, and that will make it clearer.
ifs always need thens, and you should use else when you're talking about "if this do that, otherwise do that*:
local Door = script.Parent
function onTouch(part)
Player = game.Players:GetPlayerFromCharacter(script.Parent)
if Player ~= nil then
if Player>= 2 then
Door.CanCollide = false
Door.Transparency = 0.6
else
Door.CanCollide = true
Door.Transparency = 1
end
end
end
script.Parent.Touched:connect(onTouch)
In addition to that, there are a few issues.
script.Parent isn't going to be part of a player's Character -- script.Parent is a Door.
You care about the part touching the door, which is called part. At the same time, use a local variable!
local Player = game.Players:GetPlayerFromCharacter(part.Parent)
Now, Player is a player object. It clearly won't be bigger than 2. We want to get the number of players, which, funnily is a part of the Players service and is called NumPlayers (Google things!)
if game.Players.NumPlayers >= 2 then
At the end, the connection line is correct, but Door is script.Parent already, so you should probably use that to just make it that much clearer:
Door.Touched:connect( onTouch )
1 comment
Thanks I'll see if it works