I think its like
local Door = script.Parent function onTouch(part) Player = game.Players:GetPlayerFromCharacter(script.Parent) if Player ~= nil then if Player>= 2 Door.CanCollide = false Door.Transparency = 0.6 if Players < 2 then Door.CanCollide = true Door.Transparency = 1 end end end script.Parent.Touched:connect(onTouch)
And this wont work please help
First: your syntax isn't right. You should tab your code, and that will make it clearer.
if
s always need then
s, 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 )
local Door = script.Parent script.Parent.Touched:connect(function(part) if game.Players.NumPlayers >= 2 then Door.CanCollide = false Door.Transparency = 0.6 else Door.CanCollide = true Door.Transparency = 1 end end script.Parent.Touched:connect(onTouch)
NumPlayers will tell you how many people are in the server, to use :GetPlayerFromCharacter()
you need to add game.Players:GetPlayerFromCharacter(part.Parent)
because script.Parent(which is door) is obviously not a player. http://wiki.roblox.com/index.php?title=API:Class/Players/NumPlayers