Issue with my room door script

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!
    I want it to where if my room number tool is collect it well open the door

  2. What is the issue? Include screenshots / videos if possible!
    so I’m trying to script a room door on Roblox but it prints out Room Key does not match the room number! when I have the right room number tool how the system works is it reads the room number from the number value in the too, then that is what allows the door to open but it’s not doing that here my script

local door = script.Parent.CardSystem
local part4 = script.Parent.Part4
local part5 = script.Parent.Part5
local part6 = script.Parent.Part6
local part7 = script.Parent.Part7
local transparencyValue = 1
local originalTransparency = door.Transparency
local originalCanCollide = door.CanCollide
local roomNumber = door:GetAttribute("RoomNumber") 
print("Door's Room Number:", roomNumber) 

local function revertProperties()
	door.Transparency = originalTransparency
	part4.Transparency = originalTransparency
	part5.Transparency = originalTransparency
	part6.Transparency = originalTransparency
	part7.Transparency = originalTransparency
	door.CanCollide = originalCanCollide
end

local function onTouched(hit)
	local character = hit.Parent
	if character and hit.Parent then
		local humanoid = character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local player = game.Players:GetPlayerFromCharacter(character)
			if player then
				local backpack = player:FindFirstChild("Backpack")
				local tool = backpack:FindFirstChild("Room Key") or character:FindFirstChild("Room Key")
				if tool then
					local roomKeyValue = tool:FindFirstChild("RoomNumber")
					if roomKeyValue then
						print("Room Key's Room Number:", roomKeyValue.Value) 
					end
					if roomKeyValue and roomKeyValue.Value == roomNumber then
						door.Transparency = transparencyValue
						part4.Transparency = transparencyValue
						part5.Transparency = transparencyValue
						part6.Transparency = transparencyValue
						part7.Transparency = transparencyValue
						door.CanCollide = false

						
						delay(2, revertProperties)
					else
						print("Room Key does not match the room number!")
					end
				else
					print("Tool not found!")
				end
			end
		end
	end
end

door.Touched:Connect(onTouched)

I tested your code in a basic place and did not find the same problem, which makes me think your door’s attribute is set up incorrectly.

At the top of your script, right under the “local roomNumber = door:GetAttribute(“RoomNumber”)” put in:
print(typeof(roomNumber))

If this returns “string”, go to your door model, remove the attribute it has, and replace it with a new attribute of the same name and make sure it’s type is correctly set to “number”

Additionally - make sure your key’s “RoomNumber” number value is actually a number value and not a string value.

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