I do not understand this error

The error: [ServerScriptService.Checkpoints Script:29: attempt to index number with number]
code:

local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local checkpoints = workspace.Checkpoints
print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(
    function(plr)
        local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
        local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = plr
        local stage = Instance.new("StringValue")
        stage.Name = "Stage"
        stage.Value = obbyData or 1
        stage.Parent = stats
        local wipeouts = Instance.new("IntValue")
        wipeouts.Name = "Deaths"
        wipeouts.Value = 0
        wipeouts.Parent = stats

        local second = Instance.new("IntValue")
        second.Name = "Seconds"
        second.Value = stats
        local file = Datastore:GetAsync(plr.UserId)

        if file then
            stage.Value = file[1]
            wipeouts.Value = file[2]
            second.Value = file[3]
        end
        local char = plr.Character or plr.CharacterAdded:Wait()
        char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
        char.Humanoid.Touched:Connect(
            function(touch)
                if touch.Parent == checkpoints then
                    if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
                        stage.Value = touch.Name
                        pcall(
                            function()
                                Datastore:SetAsync(
                                    plr.UserId .. "-obbyStageProgress",
                                    {plr.leaderstats.Stage.Value, plr.Deaths.Value, plr.Seconds.Value}
                                )
                            end
                        )
                    end
                end

                game.Players.PlayerRemoving:Connect(
                    function(player)
                        Datastore:SetAsync(player.UserId, {player.leaderstats.Stage.Value, player.Deaths.Value}) -- Change "Money" with your currency.
                    end
                )
                plr.CharacterAdded:Connect(
                    function(char)
                        local hrp = char:WaitForChild("HumanoidRootPart")
                        local humanoid = char:WaitForChild("Humanoid")
                        hrp:GetPropertyChangedSignal("CFrame"):Wait()
                        hrp.CFrame = checkpoints[stage.Value].CFrame

                        humanoid.Died:Connect(
                            function(touch)
                                wipeouts.Value = wipeouts.Value + 1
                                if touch.Parent == checkpoints then
                                    if
                                        (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or
                                            touch.Name == "End"
                                     then
                                        stage.Value = touch.Name
                                        while true do
                                            wait(2)
                                            second.Value = second.Value + 1
                                        end
                                        pcall(
                                            function()
                                                game.Players.PlayerRemoving:Connect(
                                                    function(player)
                                                        Datastore:SetAsync(
                                                            plr.UserId .. "-obbyStageProgress",
                                                            {
                                                                player.leaderstats.Stage.Value,
                                                                player.Deaths.Value,
                                                                player.Seconds.Value
                                                            }
                                                        )
                                                    end
                                                )
                                            end
                                        )
                                    end
                                end
                            end
                        )
                    end
                )
            end
        )
    end
)
			
					
					
					
	
				
		



	```
1 Like

Just to clarify, but is this the line where you’re experienceing the error?

wipeouts.Value = file[2]
 

I think it was that or

wipeouts.Value = file [1]
1 Like

The error is on line 29. (30characters)

I think this may be caused by the server being unable to save your data in time. Try calling game:BindToClose method with a function that kicks every player, and waits for some time. This will allow the code connected to PlayerRemoving to run for every player before the server actually shuts down.

local Players = game:GetService("Players")

game:BindToClose(function()
    for _, Player in pairs(Players:GetPlayers()) do
        Player:Kick("This server is shutting down")
    end
    wait(3)
end)

Where do i put this? it will be helpful if you pasted it in to the full code

It can go anywhere, in any server-sided script. It’s fine if you just place it at the end of your script, though.

I tried this but my problem has not been fixed. I am stage 7 in the obby but it spawns me at stage 1.

local dss = game:GetService("DataStoreService")
local Datastore = dss:GetDataStore("ObbyData")
local checkpoints = workspace.Checkpoints
					
	local Players = game:GetService("Players")

game:BindToClose(function()
    for _, Player in pairs(Players:GetPlayers()) do
        Player:Kick("This server is shutting down")
    end
    wait(3)
end)local Players = game:GetService("Players")

print("Checkpoints leaderstats working")
print("Deaths leaderstats working")
print("Time leaderstats working")
game.Players.PlayerAdded:Connect(
    function(plr)
        local obbyData = Datastore:GetAsync(plr.UserId .. "-obbyStageProgress")
        local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
        stats.Parent = plr
        local stage = Instance.new("StringValue")
        stage.Name = "Stage"
        stage.Value = obbyData or 1
        stage.Parent = stats
        local wipeouts = Instance.new("IntValue")
        wipeouts.Name = "Deaths"
        wipeouts.Value = 0
        wipeouts.Parent = stats

        local second = Instance.new("IntValue")
        second.Name = "Seconds"
        second.Value = stats
        local file = Datastore:GetAsync(plr.UserId)

        if file then
            stage.Value = file[1]
            wipeouts.Value = file[2]
            second.Value = file[3]
        end
        local char = plr.Character or plr.CharacterAdded:Wait()
        char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame
        char.Humanoid.Touched:Connect(
            function(touch)
                if touch.Parent == checkpoints then
                    if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
                        stage.Value = touch.Name
                        pcall(
                            function()
                                Datastore:SetAsync(
                                    plr.UserId .. "-obbyStageProgress",
                                    {plr.leaderstats.Stage.Value, plr.Deaths.Value, plr.Seconds.Value}
                                )
                            end
                        )
                    end
                end

                game.Players.PlayerRemoving:Connect(
                    function(player)
                        Datastore:SetAsync(player.UserId, {player.leaderstats.Stage.Value, player.Deaths.Value}) -- Change "Money" with your currency.
                    end
                )
                plr.CharacterAdded:Connect(
                    function(char)
                        local hrp = char:WaitForChild("HumanoidRootPart")
                        local humanoid = char:WaitForChild("Humanoid")
                        hrp:GetPropertyChangedSignal("CFrame"):Wait()
                        hrp.CFrame = checkpoints[stage.Value].CFrame

                        humanoid.Died:Connect(
                            function(touch)
                                wipeouts.Value = wipeouts.Value + 1
                                if touch.Parent == checkpoints then
                                    if
                                        (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or
                                            touch.Name == "End"
                                     then
                                        stage.Value = touch.Name
                                        while true do
                                            wait(2)
                                            second.Value = second.Value + 1
                                        end
                                        pcall(
                                            function()
                                                game.Players.PlayerRemoving:Connect(
                                                    function(player)
                                                        Datastore:SetAsync(
                                                            plr.UserId .. "-obbyStageProgress",
                                                            {
                                                                player.leaderstats.Stage.Value,
                                                                player.Deaths.Value,
                                                                player.Seconds.Value
                                                            }
                                                        )
                                                    end
                                                )
                                            end
                                        )
                                    end
                                end
                            end
                        )
                    end
                )
            end
        )
    end
)
			
					

				
		



	```
This is my error: [17:12:49.362 - ServerScriptService.Checkpoints Script:38: attempt to index number with number]

17:12:49.362 - Stack Begin

[17:12:49.363 - Script 'ServerScriptService.Checkpoints Script', Line 38]

17:12:49.363 - Stack End

Also, my seconds value is not showing up in my leaderboard.

I have solved my problem with the seconds but I still have the other problem.