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
