Data save checkpoints | Roblox studio TUTORIAL
Thanks for watching!
YOU WILL NEED TO CHANGE SOMETHING IN THE SCRIPT "moveStage" BEACUSE YOUTUBE ISN'T LETTING ME TO PUT THE ANGLED BRACKET in the description
Codes:
CheckpointSave
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData")
local function SavePlayerData(player)
local success,errormsg = pcall(function()
local SaveData = {}
for i,stats in pairs(player.leaderstats:GetChildren()) do
SaveData[stats.Name] = stats.Value
end
SaveDataStore:SetAsync(player.UserId,SaveData)
end)
if not success then
return errormsg
end
end
Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = player
local Stage = Instance.new("StringValue")
Stage.Name = "Stage"
Stage.Parent = Stats
Stage.Value = 1
local Data = SaveDataStore:GetAsync(player.UserId)
if Data then
print(Data.Stage)
for i,stats in pairs(Stats:GetChildren()) do
stats.Value = Data[stats.Name]
end
else
print(player.Name .. " has no data.")
end
player.CharacterAdded:Connect(function(character)
local Humanoid = character:WaitForChild("Humanoid")
local Torso = character:WaitForChild("HumanoidRootPart")
wait()
if Torso and Humanoid then
if Stage.Value ~= 0 then
local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
Torso.CFrame = StagePart.CFrame + Vector3.new(0,1,0)
end
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end)
game:BindToClose(function()
for i,player in pairs(Players:GetPlayers()) do
local errormsg = SavePlayerData(player)
if errormsg then
warn(errormsg)
end
end
wait(2)
end)
--------------------------------------------------------------------------------------
moveStage
local Stages = workspace:WaitForChild("Stages")
for i,Stage in pairs(Stages:GetChildren()) do
Stage.Touched:Connect(function(touch)
local humanoid
if touch.Parent:FindFirstChild("Humanoid") then
humanoid = touch.Parent.Humanoid
end
if touch.Parent and touch.Parent.Parent:FindFirstChild("Humanoid") then
humanoid = touch.Parent.Parent.Humanoid
end
if humanoid then
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local PlayerStage = player.leaderstats.Stage.Value
if tonumber(Stage.Name) == PlayerStage + 1 then
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
elseif tonumber(Stage.Name) is higher PlayerStage + 1 then -- change the "is higher" for the angled bracket is higher
humanoid.Health = 0
end
end
end
end)
-----------------------------------------------------------------------------------
Twitch: https://www.twitch.tv/the_lovjak
Twitter 🐦: https://twitter.com/ThE_LovJak
Discord: https://discord.gg/bcCFBdZ8dm
Subscribe to JakLov: https://www.youtube.com/channel/UCZYHTvHRCqAvNAaiBJZw0Rg
how to make so when a player touches a checkpoint, leaves and joins back and he will be at that checkpoint
#roblox #tutorial
Other Videos By LovJak
Other Statistics
Roblox Statistics For LovJak
Currently, LovJak has 127,722 views for Roblox across 80 videos. His channel uploaded 9 hours worth of Roblox videos, or 26.34% of the total watchable video on LovJak's YouTube channel.