You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
When the players join and spawn where they left -
What is the issue? Include screenshots/videos if possible!
When the player joins their progress are saved at each stage they go to but the issue is when they join back they go to the beginning of the game it doesn’t teleport them at the stage they left off -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried youtube videos and bought Roblox coding books for help but that didn’t work either but they didn’t seem to help and I’m still stuck in this situation
This script is DataStoreScript
local d,t,rs = game:GetService('DataStoreService'):GetDataStore('nillll'),{},game:GetService('RunService')
_G.ls,_G.s = {},{} if not rs:IsStudio() then
function get(id,s,m,data)
s,m = pcall(function()
data = d:GetAsync(id)
end)
wait()
if not s then
warn('Failed to save data for '..id..' | Reason : '..m)
return(get(id))
else
return(data)
end
end
function check(data,id)
if not data then
return({
Stage = 1,
Restart = 0,
})
elseif data == 0 then
print('Loaded data value is 0 which is abnormal, retrying...')
return(check(get(id)))
else
return data
end
end
game.Players.PlayerAdded:connect(function(plr) plr.RespawnLocation = workspace.Stages[1] warn(plr.Name..' has added!')
_G[plr.UserId] = get(plr.UserId)
if game.Players:GetPlayerByUserId(plr.UserId) then
_G[plr.UserId] = check(_G[plr.UserId],plr.UserId)
_G.ls[plr.UserId] = Instance.new('IntValue',plr)
_G.ls[plr.UserId].Name,_G.s[plr.UserId] = 'leaderstats',Instance.new('IntValue',_G.ls[plr.UserId])
_G.s[plr.UserId].Name,_G.s[plr.UserId].Value = 'Stages',_G[plr.UserId].Stage
plr.RespawnLocation = workspace.Stages[_G[plr.UserId].Stage]
plr.CharacterAdded:Connect(function(char,charr)
if char:FindFirstChild('HumanoidRootPart') then
charr= plr.Character:WaitForChild('HumanoidRootPart')
end
wait()
-- charr.CFrame = workspace.Stages[_G[plr.UserId].Stage].CFrame+Vector3.new(0,5,0)
game.ReplicatedStorage.RespawnEvent:FireClient(plr,{})
plr.Character:FindFirstChildOfClass('Humanoid').Died:Connect(function()
plr:LoadCharacter()
end)
end)
plr:LoadCharacter()
else
warn(plr.Name..' has quitted the game before the data get loaded!')
end
end)
game.ReplicatedStorage.DataStore.OnServerEvent:Connect(function(plr,data,asd)
if data == 'restart' then
data,asd = pcall(function() d:SetAsync(plr.UserId,{Stage = 1,Restart = _G[plr.UserId].Restart+1}) end)
if data then
game.ReplicatedStorage.DataStore:FireClient(plr,'restarted')
_G[plr.UserId].Stage,_G.s[plr.UserId].Value,plr.RespawnLocation = 1,1,workspace.Stages[1]
wait(1)
plr.Character:FindFirstChildOfClass('Humanoid').Health = 0
else
game.ReplicatedStorage.DataStore:FireClient(plr,asd)
end
end
end)
for i,v in pairs(workspace.Stages:GetChildren()) do
i=v.Name:match('(%d+)')
if i then i=tonumber(v.Name)
v.Touched:Connect(function(hum,player)
if hum.Parent:FindFirstChildOfClass('Humanoid') then
player = game.Players:GetPlayerFromCharacter(hum.Parent)
if player and _G.s[player.UserId] then
if _G.s[player.UserId].Value<i then
_G.s[player.UserId].Value,_G[player.UserId].Stage,player.RespawnLocation =i,i,workspace.Stages[i]
print(player.Name..' has reached '..i..' stage!')
end
end
end
end)
end
end
-- Auto save
game.Players.PlayerRemoving:Connect(function(plr)
if _G[plr.UserId] then
d:SetAsync(plr.UserId,_G[plr.UserId])
_G[plr.UserId]= nil
end
end)
end
Obby Handler Code
local obbyStages = workspace:WaitForChild(“ObbyStages”)
for _,stage in pairs(obbyStages:GetChildren()) do
stage.Touched:connect(function(hit)
local hum
if hit.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Humanoid
end
if hit.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
hum = hit.Parent.Parent.Humanoid
end
if hum then
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
local plrStage = plr.leaderstats.Stage.Value
if tonumber(stage.Name) == plrStage + 1 then
plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
elseif tonumber(stage.Name) > plrStage + 1 then
hum.Health = 0
end
end
end)
end
Sorry for copying the whole code but I honestly don’t know what is wrong on why is it not teleporting the character to where they left off