DataStore can't be accessed from client

I’m trying to make an OS game but when I test the game it first says DataStore can’t be accessed from client and the save button does nothing. What could I be doing wrong and how could I fix it?

local DataStoreService = game:GetService("DataStoreService")

local DATA_STORE_KEY = "MyDataStore"

local playerDataStore = DataStoreService:GetDataStore(DATA_STORE_KEY)

local textBox1 = script.Parent.Password
local textBox3 = script.Parent.Hint
local saveButton = script.Parent.Button
local frame = script.Parent.Parent.Parent.Parent.PasswordMaking
local err0r = script.Parent.ErrorText

local function saveText()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

	local text1 = textBox1.Text
	local text3 = textBox3.Text

	local success, errorMessage = pcall(function()
		playerDataStore:SetAsync(player.UserId .. "_Text1", text1)
		playerDataStore:SetAsync(player.UserId .. "_Text3", text3)
	end)

	if success then
		print("Text saved successfully.")
		frame.Visible = false
	else
		warn("Error while saving text: " .. errorMessage)
		err0r.Visible = true
		wait(3)
		err0r.Visible = false
	end
end

saveButton.MouseButton1Click:Connect(saveText)

The documentation says there’s no way of accessing data stored from the client

2 Likes

Run this on the Server then send the data to the Client, plus I’m not sure sure why you are doing it on the Client in the first place, that would allow Exploiters to Manipulate the data.

1 Like

Use a RemoteFunction to send a message to the server asking for the DataStore value, then send it back to the client. RemoteFunction | Roblox Creator Documentation

It looks like you can make this a server script with no issues except for these lines:

You will need to send this to the server.