Is it an obby game? If it is, make sure all checkpoints (the stages) are all named according to their order (number of stage). The first stage must be a SpawnLocation, make sure AllowTeamChangeOnTouch is turned off and Neutral is turned on.
I recommend adding Stage value in the leaderstats too. The DataStore script should be looking like this:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("MoneyStats")
local function create(player)
local userId = player.UserId
local key = "Player_" .. userId
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local currency = Instance.new("IntValue", folder)
currency.Name = "Money"
local stages = Instance.new("IntValue", folder)
stages.Name = "Stage"
local data
local success, result = pcall(function()
data = DataStore:GetAsync(userId)
end)
if success and data then
currency.Value = data[1] or 0
stages.Value = data[2] or 1
else
print("Error!" .. result)
end
end
local function save(player)
local userId = player.UserId
local key = "Player_" .. userId
local leaderstats = player:FindFirstChild
local DataToSave = {
player.leaderstats.Money.Value
player.leaderstats.Stage.Value
}
local success, result = pcall(function()
DataStore:SetAsync(userId, DataToSave)
end)
if success then
print("Success!")
else
print("Error!")
warn(result)
end
end
game.Players.PlayerAdded:Connect(create)
game.Players.PlayerRemoving:Connect(save)
game:BindToClose(function()
if game:GetService("RunService"):IsStudio() then return end
for _, plr in pairs(game.Players:GetPlayers) do
save(plr)
end
end)
Then, you create another script in ServerScriptService for the checkpoints/stages, name it "CheckpointSystem".
game.Workspace.ChildAdded:Connect(function(char)
local plr = game.Players:GetPlayerFromCharacter(char)
if plr ~= nil then
local leaderstats = plr.leaderstats
local stage = game.Workspace.StagesFolder:FindFirstChild(leaderstats.Stage.Value)
if char:FindFirstChild("HumanoidRootPart") then
char.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,3,0)
wait()
char.HumanoidRootPart.CFrame = stage.CFrame + Vector3.new(0,3,0)
end
end
end)
And lastly, this code will function when a player touches a checkpoint, so you put this script in ALL CHECKPOINTS! (except for the first checkpoint)
local Players = game:GetService("Players")
local part = script.Parent
local function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and Players:GetPlayerFromCharacter(hit.Parent) then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local ls = plr:FindFirstChild("leaderstats")
if ls.Stage.Value < tonumber(part.Name) and ls.Stage.Value == ((tonumber(bricklol.Name)) - 1) then
ls.Stage.Value = tonumber(bricklol.Name)
ls.Money.Value = ls.Money.Value + 100
end
end
end
part.Touched:Connect(onTouched)
Hope this helps! This took me hours to type this myself and let me know if there are errors or simple mistakes I did. Have a good day! ^^
3 comments
Oops I forgot to make the money system in the checkpoints script
In line 12, make another line by pressing Enter, then type "ls.Money.Value = ls.Money.Value + 100"
Ok I edited it