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)