Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Thanks for using this script
- This script was made by Joriangames/BloxianCode
- Want to know how to use this and script explanation?
- Check the video here: https://youtu.be/SIW3Vq-DjZI
- ]]
- local DS = game:GetService("DataStoreService")
- local stageDS = DS:GetDataStore("stageDS")
- local spawnsFolder = game.Workspace.Spawns
- game.Players.PlayerAdded:Connect(function(plr)
- local lead = Instance.new("Folder", plr)
- lead.Name = 'leaderstats'
- local stage = Instance.new("IntValue", lead)
- stage.Name = "Stage"
- stage.Value = 0
- plr.CharacterAdded:Connect(function(char)
- local hum = char:WaitForChild("Humanoid")
- wait()
- char:MoveTo(spawnsFolder[stage.Value].Position)
- hum.Touched:Connect(function(hit)
- if hit.Parent == spawnsFolder then
- print("Player touched a spawn")
- if tonumber(hit.Name) == stage.Value +1 then
- stage.Value = stage.Value +1
- end
- end
- end)
- end)
- local data
- local success, err = pcall(function()
- data = stageDS:GetAsync(plr.UserId.."-stage")
- end)
- if success then
- if data then
- print("There was a value saved")
- stage.Value = data
- local char = plr.Character or plr.CharacterAdded:Wait()
- char:WaitForChild("HumanoidRootPart").CFrame = spawnsFolder[data].CFrame + Vector3.new(0,5,0)
- else
- local char = plr.Character
- char:WaitForChild("HumanoidRootPart").CFrame = spawnsFolder["0"].CFrame + Vector3.new(0,5,0)
- end
- else
- warn("An error occurred while checking datastore for "..plr.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(plr)
- print(plr.Name.." is leaving the game")
- local data = plr.leaderstats.Stage.Value
- local succ, err = pcall(function()
- stageDS:SetAsync(plr.UserId.."-stage", data)
- end)
- if succ then
- print("Succesfully saved the stage to the datastore")
- else
- print("An error occured while saving the stage-data for "..plr.Name)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment