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

How to make a DataStore to save a parts position?

I'm trying to make a datastore that saves the position of a part, how do I do this?

local DataStore = game:GetService("DataStoreService"):GetDataStore("DerrickPosition")
local Derrick = workspace:WaitForChild("Derrick")
game.Players.PlayerAdded:connect(function(plr)
	local uniquekey = "id"..plr.userId
	--LeaderStats
	local leaderstats = Instance.new("IntValue", plr)
	leaderstats.Name = "leaderstats"
	local Money = Instance.new("IntValue", leaderstats)
	Money.Name = "Money"
	--Saving
	local key = "user-"..plr.userId
	local saveValue = DataStore:GetAsync(key)
	
	if saveValue ~= nil then
		-- Save Format: {money, Position} Tables
		Money.Value = saveValue[1]
		Derrick.Position = saveValue[2]
	else
		local valueToSave = {Money.Value, Derrick.Position}
		DataStore:SetAsync(key, valueToSave)
	end
end)
game.Players.PlayerRemoving:connect(function(plr)
	local key = "user-"..plr.userId
	local valueToSave = {plr.leaderstats.Money.Value, Derrick.Position}
	DataStore:SetAsync(key, valueToSave)
end)

1 comment

0

You haven't tried to save it, so don't expect any scripts.

2 answers

✓ Accepted answer

YOU CANNOT STORE "userdata" VALUES (Vector3, Udim2, Faces, Color3, etc) use an lua "table" instead:


-- Replace all "Derrick.Position"s to:

{X=Derrick.Position.X,Y=Derrick.Position.Y,Z=Derrick.Position.Z}

-- and if you ever require referencing certain values:

tablenamehere[X]
tablenamehere[Y]
tablenamehere[Z]

Just save the position of the part....? Either that or your question needs more detail.

2 comments

0

You can't save Vector3 values.

0

Save the co-ordinates in a table... You really have noidea how to script I would think. TABLES ARE A MANS BEST FRIEND.

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