If statement not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    My game has a mechanic where a player can open locked doors with either a key card or a normal card.

  2. What is the issue? Include screenshots / videos if possible!
    This shows up in the output

Key Card is not a valid member of Model "Workspace.UN52099841"
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have renamed the items, and rewrote the script. There’s an “or” in the if statement so I do not understand why it’s not working.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local tweenService = game:GetService("TweenService")

local hinge = script.Parent.Parent.Hinge

local openGoal = {}
openGoal.CFrame = hinge.CFrame * CFrame.Angles(0, math.pi/2, 0)

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local openTween = tweenService:Create(hinge, tweenInfo, openGoal)

local keyCardReader = script.Parent
local indicator = keyCardReader.KeyCardIndicator

local prompt = keyCardReader.ProximityPrompt

prompt.Triggered:Connect(function(player)
	
	if player.Character["Key Card"] or player.Character["Card"] then
		
		indicator.BrickColor = BrickColor.new("New Yeller")
		wait(5)
		if math.random(1, 2) == 1 then
			
			indicator.BrickColor = BrickColor.new("Lime green")
			player.Character["Key Card"]:Destroy()
			openTween:Play()
			if math.random(1, 2) == 2 then
				
				player.Character["Card"]:Destroy()
				
			end
			prompt:Destroy()
			
		else
			
			indicator.BrickColor = BrickColor.new("Really red")
			
		end
		
	end
	
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Use :FindFirstChild() instead of [""]

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