Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Answered] Datastore won't save CFrame?

Hello, I was having a issue with the datastores. I wanted to save my model primary part CFrame, but when I go to the game again, the CFrameVall is null. Any idea how to fix this issue?

game.Players.PlayerRemoving:Connect(function(Player)
	print('Saving Data For Player '.. Player.Name)
	
	-- Builds
	
	local BuildsValue = {}
	
	for i,v in pairs(game.Workspace.truc.PlacedObject:GetChildren()) do
		local cframe = v:GetPrimaryPartCFrame()
		print(cframe)
		local New = {['Object'] = v.Name, ['CFrameVal'] = cframe, ['I'] = v.WhereVal.Value}
		table.insert(BuildsValue,New)
	end
	
	local BuildEncode = HS:JSONEncode(BuildsValue)
	PlrDS:SetAsync("Builds-"..Player.UserId,BuildEncode)
	
end)

1 comment

0

might be worth splitting up the compnents of the cframe and save them as float/number values. though that would bloat your script a little. Look at https://developer.roblox.com/en-us/api-reference/datatype/CFrame @ the bitCFrame:GetComponents ( ) function section

1 answer

Hello, I found out how! I just needed to put the CFrame in a table just like this:

{cframe:GetComponents()}

and then to get it back just do this:

table.unpack(cframe)

Hope this helped someone!

This discussion is preserved as it was. New answers, comments, and votes are closed.