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:
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())
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.