I'm trying to make a simple loop that levels a player up every 30 seconds. At first I was getting a nil value because I assumed that the folder "LevelsInfo" hadn't been created yet. I added a WaitForChild function to wait for the instance to appear within the player, but that didn't work either. The error I'm currently getting with the provided script below is: ServerScriptService.LevelSetUp:32 attempt to index nil with 'WaitForChild'
game.Players.PlayerAdded:Connect(function(player)
local levelInfo = Instance.new("Folder")
levelInfo.Name = "LevelsInfo"
levelInfo.Parent = player
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
level.Parent = levelInfo
local exp = Instance.new("IntValue")
exp.Name = "Experience"
exp.Value = 0
exp.Parent = levelInfo
local xpNeeded = 5 * 1.01 ^ level.Value
exp.Changed:Connect(function(newExp)
if newExp >= xpNeeded then
level.Value +=1
exp.Value -=xpNeeded
xpNeeded = 5 * 1.01
end
end)
end)
local function levelUp()
player.LevelsInfo.Experience.Value = player.LevelsInfo.Experience.Value + 1
wait (30)
end
player:WaitForChild("LevelsInfo"):levelUp()
