Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone Help with my Player Door script?

Asked by
2lerr 0
2 years ago
Edited 2 years ago

Can someone Help me with this line of code im trying to make it where everyone but one person can enter through the door, as a joke with my friends but i cant seem to get this line of code to work...

*local player = game.Players.LocalPlayer local door = workspace.door local userid = 152449429

if player:GetUserId(userid) if local userid = 152449429 then door.CanCollide = true else door.CanCollide = false if not userid = 152449429 end end *

1 answer

Log in to vote
0
Answered by 2 years ago

if statements have a format of

if (condition) then
    CODE A
else 
    CODE B
end

where CODE A runs when the condition returns true and if you include an else then it run CODE B if it doesn't return true.

another thing is, you can get and check a player's userid by doing player.UserId == userid rather than player:GetUserId(userid) if local userid = 152449429

the double equal sign in player.UserId == userid is a comparison operator meaning it compares two values and if it is equal it will return true

a single equal sign is an assignment operator which assigns a variable to a value

so rather than

if player:GetUserId(userid) if local userid = 152449429 then 
    CODE A
else
    CODE B
if not userid = 152449429 end end

it should be

if player.UserId == userid then
    CODE A
else
    CODE B
end

you shouldnt do local userid = 152449429 in the condition of the if statement because you've already declared that variable and it doesn't make sense.

also,

you don't need an elseif since it's just checking if the player's userid is the correct userid

but if you want an elseif you can do it like

if (condition) then
    CODE A
elseif (condition then
    CODE B
end

otherwise it should look something like

local player = game.Players.LocalPlayer
local door = workspace.door 
local userid = 152449429

if player.UserId == userid then
    door.CanCollide = true 
else 
    door.CanCollide = false 
end 

1
Don't forget not to use a server-side script but rather a localscript. Miniller 562 — 2y
Ad

Answer this question