Hello, I have this save location script here, but it deosn’t work please help me.
local ds1 = ds:GetDataStore("PositionSavingSystem")
game.Players.PlayerAdded:Connect(function(player)
local pos = player:FindFirstChild("Position")
if not pos then
pos = Instance.new("Vector3Value", player)
pos.Name = "Position"
end
local userData
local success, error = pcall(function()
userData = ds1:GetAsync(player.UserId)
end)
if success and userData then
local humanoidRootPart = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
humanoidRootPart.CFrame = CFrame.new(userData.x, userData.y, userData.z)
end
else
ds1:SetAsync(player.UserId, {
x = 0,
y = 3,
z = 0
})
userData = {
x = 0,
y = 3,
z = 0
}
end
player.CharacterAdded:Connect(function(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while true do
wait(5)
userData = {
x = humanoidRootPart.Position.X,
y = humanoidRootPart.Position.Y,
z = humanoidRootPart.Position.Z
}
pos.Value = humanoidRootPart.Position
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local pos = player:FindFirstChild("Position")
if pos then
ds1:SetAsync(player.UserId, {
x = pos.Value.X,
y = pos.Value.Y,
z = pos.Value.Z
})
end
end)