Hello, I have this script that saves the last players location. When I leave from the game and I rejoin ti works good. But when I publish the game from studio and i join from roblox I respawn. Can someone help me, so when I publish the game the savelocation will still work without any problem?
local store = DataStore:GetDataStore("PlayerCharacterInfo") -- don't change the name of the DataStore or all data on it will be reset
local joined = false
game.Players.PlayerAdded:Connect(function(plr) --runs when the player joins
plr.CharacterAdded:Connect(function() --waits for the player character to be added to the game
if joined == false then
joined = true
--store:RemoveAsync(plr.UserId) --This code will Delete the last location just in case you want to reset a player's data for testing
local playerdata = store:GetAsync(plr.UserId)
if playerdata then --tests if the player joined the game before
plr.Character.HumanoidRootPart.CFrame = CFrame.new(playerdata[1], playerdata[2], playerdata[3]) --updats the player's Posistion if they joined before
end
wait(4)
while wait() and plr do --updates the play's Position every few seconds (5-15 seconds)
if plr then
local save = {}
table.insert(save,plr.Character.HumanoidRootPart.CFrame.Position.X)
table.insert(save,plr.Character.HumanoidRootPart.CFrame.Position.Y)
table.insert(save,plr.Character.HumanoidRootPart.CFrame.Position.Z)
store:SetAsync(plr.UserId,save)
end --if character loaded
end --while loop
end -- if they just joined
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
end)