How do I datastore position and other Factors?

I’m making a game that uses the same note placement system like “a dream you’ve had before”

I’ve got a note placement system working perfectly fine but I’m unsure on how datastores work and how I would make one to save notes universally.

Here’s my scripts if it helps:

Client (Note Placement)

local remoteEventsFolder = game.ReplicatedStorage.RemoteEvents
local placeNoteRequestEvent = remoteEventsFolder.RequestNotePlacement
local placeNoteEvent = remoteEventsFolder.PlaceNote

local cas = game:GetService("ContextActionService")

local player = game.Players.LocalPlayer
local mosue = player:GetMouse()
local runService = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera

local noteText = nil

local canPlace = true
local rotation = 0
local enabled = true

local placementValidator = require(game.ReplicatedStorage.PlacementValidator)

local noteAssets = game.ReplicatedStorage.NoteAssets
local requestNotePlacement = remoteEventsFolder.RequestNotePlacement

local yBuildingOffset = .3
local maxPlacementDistance = 10
local rKeyPressed = false
local placingNote = false

local preview = nil

local castParams = RaycastParams.new()
castParams:AddToFilter(script.Parent)

local function preparePreviewNote(note)
	preview = note:Clone()
	preview.Transparency = .5
	preview.CanCollide = false
	preview.CanQuery = false
	preview.Parent = workspace
	rotation = 0
end

local function renderPreviewNote()
	if uis:IsKeyDown(Enum.KeyCode.R) then
		rotation += 1
	end
	
	if not placementValidator.IsWithinMaxDistance(player, preview.Position) then
		preview.Color = Color3.fromRGB(255, 0, 0)
		canPlace = false
	else
		preview.Color = Color3.fromRGB(0, 255, 0)
		canPlace = true
	end
	
	if preview.Position.Y < yBuildingOffset then
		preview.Color = Color3.fromRGB(0, 255, 0)
		canPlace = true
	else
		canPlace = false
		preview.Color = Color3.fromRGB(255, 0, 0)
	end
	local mouseLocation = uis:GetMouseLocation()
	local unitRay = camera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
	
	local cast = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, castParams)
	if cast and preview then
		preview.Orientation = Vector3.new(0, rotation, 0)
		preview.Position = cast.Position + cast.Normal * noteAssets.GhostNote.Size.Y/2
	end
end

local function placeNote(_name, inputState, _inputObj)
	if inputState == Enum.UserInputState.Begin then
		if canPlace then
				placeNoteEvent:FireServer(preview.Position, preview.Orientation, noteText)
				runService:UnbindFromRenderStep("RenderPreview")
				cas:UnbindAction("Place")
				preview:Destroy()
				preview = nil
		end
	end
end

remoteEventsFolder.SubmitNoteText.OnClientEvent:Connect(function(text)
		noteText = text
		preparePreviewNote(noteAssets.GhostNote)
		runService:BindToRenderStep("RenderPreview", Enum.RenderPriority.Camera.Value, renderPreviewNote)
		cas:BindAction("Place", placeNote, false, Enum.UserInputType.MouseButton1)
end)

Server (PlacementSystem)

local remoteEventsFolder = game.ReplicatedStorage.RemoteEvents
local placeNoteEvent = remoteEventsFolder.PlaceNote
local noteTemplate = game.ReplicatedStorage.NoteAssets.Note

remoteEventsFolder.RequestNoteText.OnServerEvent:Connect(function(player, text)
	remoteEventsFolder.SubmitNoteText:FireClient(player, text)
end)

local function placeNote(player, position, rotation, text)
	local note = noteTemplate:Clone()
	note.Parent = workspace
	note.Position = position
	note.Orientation = rotation
	note.NoteGui.Holder.PlayerName.Text = "- "..player.Character.Name
	note.NoteGui.Holder.NoteText.Text = text
end



placeNoteEvent.OnServerEvent:Connect(placeNote)

Module (PlacementValidator)

local MAX_DISTANCE = 10

local PlacementValidator = {}

function PlacementValidator.IsWithinMaxDistance(player, position)
	local playerPos = player.Character and player.Character:GetPivot().Position
	if not playerPos then return false end
	
	return (position - playerPos).Magnitude <= MAX_DISTANCE
end

return PlacementValidator

Client (Text Reciever)

local remoteEventsFolder = game.ReplicatedStorage.RemoteEvents
local placeNoteEvent = remoteEventsFolder.PlaceNote
local requestNoteText = remoteEventsFolder.RequestNoteText

local player = game.Players.LocalPlayer

script.Parent.WriteFrame.Cancel.MouseButton1Click:Connect(function()
	script.Parent.Enabled = false
end)

script.Parent.WriteFrame.Confirm.MouseButton1Click:Connect(function()
	script.Parent.Enabled = false
	requestNoteText:FireServer(script.Parent.WriteFrame.TextBox.Text)
end)

remoteEventsFolder.RequestNotePlacement.OnClientEvent:Connect(function()
	script.Parent.Enabled = true
end)

I know its a lot :confused:

But I’ve never messed with datastores and any help would be appreciated.

I also heard of something called a memory store and I’m unfamiliar with that too.

Have you never used datastore before?
If not its probably best to look up a more detailed explanation, but in the most basic sense they’re just big tables that you can store and get values in using GetAsync and SetAsync (or get and then set a value with UpdateAsync)
Random Devforum post about datastores
A youtube video on datastores if you want that for some reaosn

All you really have to do to save a note is to store the unique data about it. This would include things like position, text, and whatever else is customizable. (But not things that are shared for all notes, such as collision or transparency unless you want those to be custom too)

Normally you’d be saving data per player, but in this case, it probably makes more sense to save the notes based on location.
One way you can do this is to have a big table of all the notes on a wall, and give each wall a unique ID which can be used as the key in the datastore. You can then load in any notes you need when a wall gets close enough to a player
Another idea could be to split the entire world into small chunks, and then you can store every note in a chunk to a key. You can then load in notes chunk by chunk based on player distance.
I assume “a dream you’ve had before” stores them per room and requests for the notes whenever a new room is loaded

Oh right almost forgot to mention
you cant directly store instances into datastores, and I cant really remember if you could store things like vectors
If any of them don’t work, you can turn them into another form of data such as a string or table

for example, assuming vectors cant be stored (i forgot if they could or not), then the vector Vector3.new(5, 3, 2) could be stored as {5, 3, 2} or {X=5, Y=3, Z=2}