I have a script in which every second the DataStore stores the postion into the vector3value. In my script this doesn't work. When the person leaves the game the person will spawn back from his/her last position. Can anyone help about what I am doing wrong? thank you!
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayersPos") game.Players.PlayerAdded:connect(function(player) local character = workspace:FindFirstChild(player.Name) local humanroot = character:FindFirstChild("HumanoidRootPart") local position = humanroot.Position local key = "key-"..player.userId local folder = Instance.new("Folder",player) folder.Name = "Vector3Value" local cpos = folder.Value cpos = position local save = DataStore:GetAsync(key) if save then cpos = save[1] else local load = {cpos} DataStore:SetAsync(key,load) end end) game.Players.PlayerRemoving:connect(function(player) local key = "key-"..player.userId local load = {player.Vector3Value:FindFirstChild("cpos")} DataStore:SetAsync(key,load) end)
p.s: I am not that good at data store so for those who think I am way off I am sorry :3
Changed function for local players HumaidRootPart every time a HumanoidRootPart property changes then change the value to the CFrame and when a player joins make its HumanoidRootParts' CFrame the value
connect a .Changed function for HumanoidRootPart
make the value of the random numbervalue the CFrame of the HumanoidRootPart
payer join function
player's humanoidrootpart's position is the value of the numbervalue