Elseif statement not working?

Hello, I am currently working on a door for prison game where if you are a cop it opens up but if you are a prisoner or criminal it makes a doorknob sound.

For some reason, when I use the door as a prisoner it opens up and the same thing happens as a cop.

I’ve looked at some discussions on scripting helpers and some on here but it still hasn’t solved my problem.

Here is the code:

local cd = script.Parent
local door = cd.Parent.Parent.Door

local function onClick(player)
	if player.Team == game:GetService("Teams").Prisoner then
		workspace.Sounds.doorknob:Play()
		print("they are a prisoner or criminal")
	else
			door.Transparency = 1
			door.CanCollide = false
			wait(2)
			door.Transparency = 0
			door.CanCollide = true
			print("they are a cop")
		end
	end

cd.MouseClick:Connect(onClick)

Thanks for any feedback.

1 Like

This looks fine to me. Are you really on the ‘Prisoner’ team? Is the team actually named ‘Prisoner’?

Yes the name of the team is prisoner. I’ve tested both teams

You mean Prisoner right, not prisoner?

Yes I mean “Prisoner” not “prisoner”.

Is it a Script and not a LocalScript? Also, you might want to check the actual team by debugging with

print(player.Team)
if player.Team == game:GetService("Teams").Prisoner then

It is a server script. I tested out the debug script you gave me and it printed “Guard” when I was on the guard team but when I switched to the prisoner team it printed guard again.

1 Like

Now we know what is actually happening. It seems that there is a mistake in the process where you change teams.

Well I don’t have a team change GUI, I’m just using the teamcolor property inside of my player instance in the players service and I think it does the same as a team change GUI would.

That does not actually change your team. This article can help you with changing teams properly: Player | Roblox Creator Documentation.

1 Like

It’s an issue regarding checking if the player is on the prisoner’s team (if player.Team == game:GetService("Teams").Prisoner then). You can attempt checking for the TeamColor, followed by the prisoner’s colour, and see if that makes a change.

1 Like

I think I found out the error but it works now anyways so I will just say what I think was going wrong.

Basically I was changing the team from the client’s side instead of the server’s side and now it prints that I am on the prisoner team when I am on the prisoner team instead of saying I am a guard.