as it is the script pretty much works however i want to rearrange it a bit because right now the player is spawned instantly at 0,0,0 position before the saved data can load it, preventing the script from moving the player to the checkpoint of the level he's curently on, i've tried all sorts of combinations, but it ends up causing even more of a delay. If any1 has an idea how to make it so that the player is teleported as soon as he enters the game i'd really appriciate it as i've been struggling with it all day
Thanks for your time
local data = game:GetService("DataStoreService")
local dataStor = data:GetDataStore("MobbyProgress1")
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue",p)
stats.Name = "leaderstats"
local stage = Instance.new("IntValue",stats)
stage.Name = "Stage"
stage.Value = 0
local Trophies = Instance.new("IntValue",stats)
Trophies.Name = "Trophies"
Trophies.Value = 0
local Trophy1 = Instance.new("BoolValue",p)
Trophy1.Name = "Trophy1"
Trophy1.Value = false
local Trophy2 = Instance.new("BoolValue",p)
Trophy2.Name = "Trophy2"
Trophy2.Value = false
local Trophy3 = Instance.new("BoolValue",p)
Trophy3.Name = "Trophy3"
Trophy3.Value = false
key = 'MobbyProgress1_'..p.userId
local saveData = dataStor:GetAsync(key)
if saveData then
stage.Value = saveData[1]
Trophies.Value = saveData[2]
Trophy1.Value = saveData[3]
Trophy2.Value = saveData[4]
Trophy3.Value = saveData[5]
else
dataStor:SetAsync(key, {0,0})
end
p.CharacterAdded:Connect(function(Character)
if Character ~= nil then
local stats = p:WaitForChild("leaderstats")
local stage = game.Workspace:WaitForChild(stats.Stage.Value)
wait()
Character.Torso.CFrame = stage.CFrame + Vector3.new(0,3,0)
end
end)
game.Players.PlayerRemoving:connect(function(p)
key = 'MobbyProgress1_'..p.userId
local save = {p.leaderstats.Stage.Value, p.leaderstats.Trophies.Value,p.Trophy1.Value,
p.Trophy2.Value,p.Trophy3.Value}
dataStor:SetAsync(key, save)
end)
end)

1 comment
yes i know i should be loading it sooner but if i put it before saveData or the trophies it doesn't work, so what are you trying to say?