I made a code:
function onPlayerJoin(player)
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
It says
Global stage is only used in the enclosing function; consider changing it to local?
Global leaderstats is only used in the enclosing function; consider changing it to local?
But it is in this code as well (Different script in different object)
function stageTwo()
stage.Value = 2
end
script.Parent.Touched:connect(function(stageTwo)
stage.Value = 2
end)
So why is that error there and why does it say not defined stage and in the second code?
More importantly, how do I fix it?

2 comments
I think I need it to be global because I am making an obby and I want to make it so when you hit a checkpoint, it changes the value stage to whatever stage they are on. How do I do this?
What might be helpful in your case is to use an IntValue (Look it up on the developer hub) so that other scripts can take a look at its value to find what stage the player is on.