Help with save spawn location

ok so i need help with this i think this script should be working but here’s the thing, there is an error in the output that says “Cframe is not a valid member of TixyPix(which is my username)” btw this script is from a tutorial, but yes thats the error,i have api turned on btw, how do i fix this?
here’s the script:

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("MyLocationData")

local sessionData = {}

local function addPlayer(player)
	local data = ds:GetAsync(player.UserId)
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	if not data then
		sessionData[player] = { loc = { hrp.Cframe:GetComponents() }}
	else
		sessionData[player] = data
		local cf = CFrame.new(table.unpack(sessionData[player].loc))
		wait()
		hrp.Cframe = cf
	end
end

local function saveLocation(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hrp = char:WaitForChild("HumanoidRootPart")
	sessionData[player].loc = { hrp.Cframe:GetComponents() }
	ds:GetAsync(player.UserId, sessionData[player])
end

local function saveLoop()
	while true do
		wait(3)
		for ply, v in pairs(sessionData)do
			saveLocation(ply)
		end
	end
end

local function removePlayer(player)
	saveLocation(player)
	sessionData[player] = nil
end

game.Players.PlayerAdded:Connect(addPlayer)
game.Players.PlayerRemoving:Connect(removePlayer)

spawn(saveLoop)
3 Likes
hrp.Cframe = cf
hrp.CFrame = cf

Do you notice the difference? It’s a typo that’s causing the error!

2 Likes

you should write

hrp.Cframe = cf

with capital “f”
to be

hrp.CFrame = cf
2 Likes

ahhh okayy than u so muchhhhhhhhhh

2 Likes