If statement is not working correctly

  1. What do you want to achieve?
    I want to compare the players user id to two others, if it is the same it will open a gate. If it is not the same it will not open.

  2. What is the issue?
    The if statement is not working. Regardless of wether the players user id is different or not it still opens the gate.

  3. What solutions have you tried so far?
    I’ve tried looking everywhere but I haven’t found anything like my problem.

The function of my script is to open a gate by checking if the player id is the same as I chose.

Script:

local tweenservice = game:GetService("TweenService")
local face1 = script.Parent.FacialScanner
local face2 = script.Parent.FacialScanner2
local prompt1 = face1.PA.OpenGateDoor
local prompt2 = face2.PA.OpenGateDoor
local text1 = script.Parent.Text.TextGUI.TextLabel
local text2 = script.Parent.Text2.TextGUI.TextLabel
local color = face1.Color
local name = "134862777"
local name2 = "3724336777"

prompt1.Triggered:Connect(function(plr)
	if prompt1.Enabled == true then
		prompt1.Enabled = false
		prompt2.Enabled = false
		
		text1.Text = "Checking"
		wait(2)
		
		if plr.UserId == name or name2 then
			print(plr.Name)
			text1.Text = "Facial Recoginition Success"
			face1.Color = Color3.new(0.456626, 1, 0)
			text1.Parent.Parent.Color = Color3.new(0.456626, 1, 0)
			face1.Activate:Play()
			wait(1)
			face1.Color = color
			text1.Parent.Parent.Color = color
			
			local hinge = script.Parent.Hinge

			local openGoal = {}
			openGoal.CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(130), 0)
			
			local tweenInfo  = TweenInfo.new(
				1,
				Enum.EasingStyle.Quad,
				Enum.EasingDirection.InOut
			)

			local openDoor = tweenservice:Create(hinge, tweenInfo, openGoal)

			openDoor:Play()
			script.Parent.Chainlink.OpenSound:Play()
			wait(3)
		
			local closeGoal = {}
			closeGoal.CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(-130), 0)

			local closeDoor = tweenservice:Create(hinge, tweenInfo, closeGoal)

			closeDoor:Play()
			wait(0.5)
			script.Parent.Chainlink.CloseSound:Play()
		else
			face1.Color = Color3.new(1, 0.0542, 0)
			text1.Parent.Parent.Color = Color3.new(1, 0.0542, 0)
			text1.Text = "Imposter Detected"
			face1.Deny:Play()
			wait(1)
			face1.Color = color
			text1.Parent.Parent.Color = color
		end
		wait(2)
		text1.Text = "Facial Recoginition Required"
		text2.Text = "Facial Recoginition Required"
		prompt1.Enabled = true
		prompt2.Enabled = true
	end
end)


prompt2.Triggered:Connect(function(plr)
	if prompt2.Enabled == true then
		prompt1.Enabled = false
		prompt2.Enabled = false
		
		text2.Text = "Checking"
		wait(1)

		if plr.UserId == name or name2 then
			text2.Text = "Facial Recoginition Success"
			face2.Color = Color3.new(0.456626, 1, 0)
			text2.Parent.Parent.Color = Color3.new(0.456626, 1, 0)
			face2.Activate:Play()
			wait(1)
			face2.Color = color
			text2.Parent.Parent.Color = color

			local hinge = script.Parent.Hinge

			local openGoal = {}
			openGoal.CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(-130), 0)

			local tweenInfo  = TweenInfo.new(
				1,
				Enum.EasingStyle.Quad,
				Enum.EasingDirection.InOut
			)

			local openDoor = tweenservice:Create(hinge, tweenInfo, openGoal)

			openDoor:Play()
			script.Parent.Chainlink.OpenSound:Play()
			wait(3)

			local closeGoal = {}
			closeGoal.CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(130), 0)

			local closeDoor = tweenservice:Create(hinge, tweenInfo, closeGoal)

			closeDoor:Play()
			wait(0.5)
			script.Parent.Chainlink.CloseSound:Play()
		else
			text2.Text = "Imposter Detected"
			face2.Deny:Play()
			face2.Color = Color3.new(1, 0.0542, 0)
			text2.Parent.Parent.Color = Color3.new(1, 0.0542, 0)
			wait(1)
			face2.Color = color
			text2.Parent.Parent.Color = color
		end
		wait(2)
		text1.Text = "Facial Recoginition Required"
		text2.Text = "Facial Recoginition Required"
		prompt1.Enabled = true
		prompt2.Enabled = true
	end
end)

Instead of doing

if plr.UserId == name or name2 then

try

if plr.UserId == name or plr.UserId == name2 then

Thank you! I’ve been stuck on this for a couple of hours.

Np! I had the same problem a couple years ago. Kind of annoying how you have to add the whole line of code again after the “or” because roblox can’t understand it if you are just stating the variable.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.