Please help me solve the problem.
Error: Value of type nil cannot be converted to a number.
The script:
local dataStoreService = game:GetService("DataStoreService")
local stageStore = dataStoreService:GetDataStore( "PlayerStageDataStore")
function plrToStage(plr)
repeat wait() until plr.Character.HumanoidRootPart
local stagePart = game.workspace.Checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
if stagePart then
plr.Character.HumanoidRootPart.CFrame = stagePart.CFrame + Vector3.new(0,2.5, 0)
else
warn("Checkpoint " .. tostring(plr.leaderstats.Stage.Value) .. " not found.")
end
end
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance. new("IntValue")
stage.Name = "Stage"
stage.Parent = leaderstats
local success, errorMsg = pcall(function()
stage.Value = stageStore:GetAsync(player.UserId)
end)
if success then
print("Successfully got "..player.Name.."'s stage data.")
else
warn(errorMsg)
end
if player.Character then
plrToStage(player)
end
player.CharacterAdded:Connect(function()
plrToStage(player)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMsg = pcall(function()
stageStore:SetAsync(player.UserId,player.leagerstats. Stage.Value)
end)
if success then
print("Successfully saved "..player.Name.."'s stage data.")
else
warn(errorMsg)
end
end)
for _, checkpoint in pairs(game.Workspace.Checkpoints:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checpointNumber = tonumber(checkpoint.Name)
if player.leaderstats.Stage.Value < tonumber(checkpoint.Name) then
player.leaderstats.Stage.Value = tonumber(checkpoint.Name)
end
end
end)
end
it was written somewhere that there is such a bug, but not in roblox studio Save Data also does not work.
I will be grateful to everyone for their help.