Problem with trying to debug / find problems in my script

What I am currently trying to do is I am trying to make it so whenever a player inside the script is authorized to press the buttons, they will be able to open the door, and it will automatically close.

These are the current issues I am experiencing:

I have made several fixes that were more visible, but there are problems still that aren’t allowing me to fully function the door.

Here’s my code below:

local Door = script.Parent

local OriginalCFrame = Door.CFrame

local OpenCFrame = Door.Parent.OpenGoal.CFrame

local TweenService = game:GetService("TweenService")
local OpenSpeed = 0.65
local CloseSpeed = 0.65
local deny = Door.Deny
local accept = Door.Granted
local opensound = Door.Open
local closesound = Door.Close
local OpenTime = 3
local button = script.Parent.Parent.buttons
print("variable declarations working")
	local b1 = button.Button1
	local b2 = button.button2
print("button declaration working")
local rings = script.Parent.rings

	local r1 = rings.Ring1
	local r2 = rings.Ring2
print("ring declaration working")
local Click1 = button.Button1.ClickDetector
local Click2 = button.Button2.ClickDetector
local OpenInfo = TweenInfo.new(OpenSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local OpenGoals = {
	CFrame = OpenCFrame
}
local TweenOpen = TweenService:Create(Door, OpenInfo, OpenGoals)
local CloseInfo = TweenInfo.new(CloseSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local CloseGoals = {
	CFrame = OriginalCFrame
}
local TweenClose = TweenService:Create(Door, CloseInfo, CloseGoals)
print("tween working")
local allowed = {"79262008"}


function OpenDoor(player)
	if player.UserId ~= allowed then
		deny:Play()
		return end	
		r1.Color = Color3.new(0,1,0)
		b1.Color = Color3.new(0,1,0)
		r2.Color = Color3.new(0,1,0)
		b2.Color = Color3.new(0,1,0)

		accept:Play()
		TweenOpen:Play()
		opensound:Play()

		task.wait(OpenTime)

		r1.Color = Color3.new(1,0,0)
		b1.Color = Color3.new(1,0,0)
		r2.Color = Color3.new(1,0,0) 
		b2.Color = Color3.new(1,0,0)
		TweenClose:Play()
		closesound:Play()
	end

Click1.MouseClick:Connect(OpenDoor)
Click2.MouseClick:Connect(OpenDoor)
1 Like
local allowed = {"79262008"}

I would do a

local allowed = {79262008 = true}

So that you can do

if not allowed[player.UserId] then
    --play deny sound
    return
end

The way you’re currently doing it is checking if the players user ID happens to not be list you made which it can’t ever be because you just made the list and player ID is a number

Hi there, Thank you for giving me a method to use! I will try it when I get back to it. I am currently working on fixing some errors that printed in the output.

I have this error…
image

this is happening cause your trying to store a “variable” inside a list.

you can fix it by simply creating the variable properly and then inserting it into your list:

local allowedNumber = 79262008

local allowed = {allowedNumber}

and then checking if the number is inside allowed list as you might not have to set it’s value

what should I do here?

1 Like

could you share your code and tell me what are you using it for please?

and btw that error is showing up because your passing the first argument of table.find() as a number and not as a list

local Door = script.Parent

local OriginalCFrame = Door.CFrame

local OpenCFrame = Door.Parent.OpenGoal.CFrame

local TweenService = game:GetService("TweenService")
local OpenSpeed = 0.65
local CloseSpeed = 0.65
local deny = Door.Deny
local accept = Door.Granted
local opensound = Door.Open
local closesound = Door.Close
local OpenTime = 3
local button = script.Parent.Parent.buttons
print("variable declarations working")
	local b1 = button.Button1
	local b2 = button.Button2
print("button declaration working")
local rings = script.Parent.Parent.rings

	local r1 = rings.Ring1
	local r2 = rings.Ring2
print("ring declaration working")
local Click1 = button.Button1.ClickDetector
local Click2 = button.Button2.ClickDetector
local OpenInfo = TweenInfo.new(OpenSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local OpenGoals = {
	CFrame = OpenCFrame
}
local TweenOpen = TweenService:Create(Door, OpenInfo, OpenGoals)
local CloseInfo = TweenInfo.new(CloseSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local CloseGoals = {
	CFrame = OriginalCFrame
}
local TweenClose = TweenService:Create(Door, CloseInfo, CloseGoals)
print("tween working")

local allowed = 79262008


function OpenDoor(player)
		if table.find(allowed, player) == nil then
		deny:Play()
		return 
	end	
		r1.Color = Color3.new(0,1,0)
		b1.Color = Color3.new(0,1,0)
		r2.Color = Color3.new(0,1,0)
		b2.Color = Color3.new(0,1,0)

		accept:Play()
		TweenOpen:Play()
		opensound:Play()
	Click1.MaxActivationDistance = 0
	Click2.MaxActivationDistance = 0
		task.wait(OpenTime)

		r1.Color = Color3.new(1,0,0)
		b1.Color = Color3.new(1,0,0)
		r2.Color = Color3.new(1,0,0) 
		b2.Color = Color3.new(1,0,0)
		TweenClose:Play()
	closesound:Play()
	Click1.MaxActivationDistance = 15
	Click2.MaxActivationDistance = 15
	end

Click1.MouseClick:Connect(OpenDoor)
Click2.MouseClick:Connect(OpenDoor)

what should it be set as then?

1 Like

ok I see the problem:

local allowed = 79262008

that variable is a number thats allowed in not a table so if you want to have a table with all of your allowed numbers just swap it out for this:

local allowed = {79262008}

you can just keep adding numbers but remember to space them with a coma:

Example:
local allowed = {79262008, 56045, 463454}

Right, but I want it for specifically one person since these are office doors for one person’s office.

is that number a player’s ID? (words)

1 Like

Yes, 79262008 is my playerid in that declaration.

aight so just leave your ID alone in the table.

Example:

local allowed = {79262008}

oh and also if the argument “player” is not a number your code won’t work as table.find() uses a number to find an item within a table using it’s position.

Example:

local table = {“Hello”, “How are you”, “Pizza”}

local item = table.find(table, “Pizza”)

–This will return an error

Correct Example:

local table = {“Hello”, “How are you”, “Pizza”} --Pizza is the third item inside the table

local item = table.find(table, 3)

we use 3 to find the third item inside table which is our string “Pizza”

I found a fix to this! Instead of being “local allowed,” I decided to put

function OpenDoor(player)
		if player.UserId ~=79262008 then
		deny:Play()
		return 
	end	
1 Like

Ahh, my bad. I know you’ve already got a working version, but the reason this specifically didn’t work is because you needed to format it like this which I forgot to do

local allowed = { [79262008] = true}

The brackets were forgotten.

The reason you would go for this over your working version is because you can just add however many ids you want and still have it work.

local allowed = {
    [79262008] = true,
    [22046258] = true, --random id for example
}
1 Like

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