Help With Coding This "Get To Stage To Unlock Door Script"

So I am currently making my game where you basically do obbies and quizzes to make it to the next stage, and once you get to a certian stage, you can unlock a door to the new level.

My Issue was: I am a beginner coder/scripter so I had no idea what I was doing. Also I cant figure out how to create the variable for leaderstats. Another problem is that, well, I don’t know what I am doing wrong. Here is the code and some more stuff:

Leaderstats in explorer

local door = game.Workspace.PayDoor1

local player = game.Players.PlayerAdded

local leaderstats = player:WaitForChild("leaderstats")

door.CanCollide = true


local function OpenDoor()
	door.CanCollide = false
	
end

if leaderstats.Stage.Value < 3 then end

door.Touched:Connect(OpenDoor())

function oa(object)
local player = game.Players:playerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end


function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = object
end end

game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)

I have tried so many things like finding places videos and pictures that may help with finding the variable for leaderstats and also I tried putting the door script in the same script as the leaderstats.

If there is anything that I am doing wrong/need to be doing please let me know.

instead of having this outside of the open door function, do it inside and with >= instead of <

local door = game.Workspace.PayDoor1

local player = game.Players.PlayerAdded

local leaderstats = player:WaitForChild("leaderstats")

door.CanCollide = true


local function OpenDoor()
	if leaderstats.Stage.Value >= 3 then
		door.CanCollide = false
	end
end

door.Touched:Connect(OpenDoor())

I tried, and this is what the output is saying

When it says “WaitForChild is not a valid member of RBXScriptSignal” I think it is referring to this

local leaderstats = player:WaitForChild("leaderstats")

Nope, you can set an event as a variable.

However, you must connect it.

Cool, didn’t know that.

What script is having the issue, the one the checks the leaderstat value, or the one that creates the leaderstat?

The problem is he didn’t connect the event.

Its the one that check the value of the leaderstat

How do I connect the event? And, in which script.

Read the connecting functions here:

I read it, and it shows like I connected the event here:

door.Touched:Connect(OpenDoor())

Leave out the () so the code will be:

door.Touched:Connect(OpenDoor)

Okay, ill try that. It put itself in there when I pressed enter

That didn’t work either… The output keeps saying there is something wrong with line 5 which is why I think the variable for leaderstats is wrong. Or something else. Was the event that I had to connect the leaderstats, or was it the function, because I already connected the function.