Hello there,
-
What do I want to achieve? Make another part be the one two make the leaderstats go up by 1
-
What is the issue? The issue is that i do not know how which part of the script makes the leaderstats go up by one
Players.PlayerAdded:Connect(function(player)
local playerKey = "ID_" .. player.UserId
local retrievedData
local success, errorMessage = pcall(function()
retrievedData = ObbyDataStore:GetAsync(playerKey)
end)
if not success and not RunService:IsStudio() then
player:Kick("Error loading data, please rejoin.")
return
end
if not retrievedData then
retrievedData = {}
end
-- Create leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create stage value
local stageValue = Instance.new("IntValue")
stageValue.Name = "Level"
stageValue.Value = retrievedData.Level or FIRST_CHECKPOINT
stageValue.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
wait() -- Wait for the character to load
local checkpoint = checkpoints:FindFirstChild(tostring(stageValue.Value))
if checkpoint then
character:WaitForChild("HumanoidRootPart").CFrame = checkpoint.CFrame + Vector3.new(0, 3 + (checkpoint.Size.Y / 2), 0)
end
end)
end)
for i, v in pairs(checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player or not player:FindFirstChild("leaderstats") then
return
end
if player.leaderstats.Level.Value == tonumber(v.Name) - 1 then -- Prevents the player from skipping checkpoints and going backward
player.leaderstats.Stage.Value = tonumber(v.Name)
end
end)
end
game.Players.PlayerRemoving:Connect(function(player)
if not player:FindFirstChild("leaderstats") then
return
end
local playerKey = "ID_" .. player.UserId
local stage = player.leaderstats.Stage.Value
local success, errorMessage = pcall(function()
ObbyDataStore:SetAsync(playerKey, {Stage = stage})
end)
if not success and not RunService:IsStudio() then
warn("Error while saving player data")
end
end)
- What solutions have you tried so far? I tried looking up some vids, but they didn’t explain how the script works or the script just does not work.