Script to update player position every so often:

game.Players.PlayerAdded:Connect(function(player)
	local pos = player:WaitForChild("PlayerData").PosValue
	player.CharacterAdded:Connect(function(character)
		while true do
			wait(5)
			pos.Value = character.HumanoidRootPart.Position
		end
	end)
end)

Datastore server script:

local DSS = game:GetService("DataStoreService")
local plrposition = DSS:GetDataStore("plrPosition")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local plrdata = Instance.new("Folder")
		plrdata.Name = "PlayerData"
		plrdata.Parent = player
		
		local pos = Instance.new("Vector3Value")
		pos.Name = "PosValue"
		pos.Parent = plrdata
		pos.Value = plrposition:GetAsync(player.UserId) or character.HumanoidRootPart.Vector3
		character.HumanoidRootPart.Vector3 = Vector3.new(pos.Value)
		game.Players.PlayerRemoving:Connect(function(player)
			plrposition:SetAsync(player.UserId, pos.Value)
		end)
		while wait(15) do
			plrposition:SetAsync(player.UserId, pos.Value)
		end
	end)
end)

However, they just give some errors that I don't know how to fix. API Services are on. What it's meant to do is the first script saves the player's position every so often by setting a value to it's position. Second script is the datastore script that loads or saves the value and also loads the player's last saved position. Is there an easier or better way to do this?

7 comments

0

What are the errors?

0

Vector3 is not a valid member of Part, and possible infinite yields on :WaitForChild("PlayerData")

0

HumanoidRootPart.Position

0

Vector3 is a type of value, but to get the players Vector3 you have to use ".Position".

0

Is there anything I can do with the infinite yield?

0

Nevermind, it removed that error too. However it says i can't save Vector3 in data stores.

0

you cant save userdata only number strings booleans and tables, so turn the vector3 into an array like {X,Y,Z}