so the game I'm making is singleplayer so to make it easier most of the scripting is client-sided but to load and save data it needs to be in a normal script so I'm using some variables in replicated storage but even though the values in replicated storage but I keep getting errors saying that the values are nil even though I'm looking at it in the explorer and there are definitely number values so I need to know that I'm doing wrong here. below I have all the interactions between the server and the client
server script:
warn('dataloader started')
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local PlayerData = DataStoreService:GetDataStore('PlayerData')
local PlayerName = ReplicatedStorage.Data.Temp.PlayerName
local PKey
local Data = {
Stage = 1,
Difficulty = 2,
FlashingEnabled = 0
}
--Load data when the player joins
game.Players.PlayerAdded:Connect(function(player)
PKey = "Player_" .. player.UserId
warn('getting data from: ' .. PKey)
local extract
local Sucsess , err = pcall(function()
extract = PlayerData:GetAsync(PKey .. 'Data')
end)
if Sucsess then
Data = extract
print('Data was sucsessfully extracted')
game.ReplicatedStorage.Dataloaded:FireClient(player)
else
warn('There was an error getting data from datastore: ' .. err)
end
end)
--Save data when player leaves
game.Players.PlayerRemoving:Connect(function(player)
warn('Saving data to:' .. PKey)
local Sucsess , err = pcall(function()
PlayerData:SetAsync(PKey .. 'Data' , Data)
end)
if Sucsess then
print('Data is saved')
else
warn('There was an error saving player data: ' .. err)
end
end)
--Update the player data when function is called
game.ReplicatedStorage.DataUpdate.OnServerEvent:Connect(function()
warn('setting data')
Data.Stage = game.ReplicatedStorage.Data.Perm.Stage.Value
Data.FlashingEnabled = game.ReplicatedStorage.Data.Perm.FlashingEnabled.Value
Data.Difficulty = game.ReplicatedStorage.Data.Perm.Difficulty.Value
end)
--save when client fires event
game.ReplicatedStorage.SaveRequest.OnServerEvent:Connect(function()
warn('Saving data to:' .. PKey)
local Sucsess , err = pcall(function()
PlayerData:SetAsync(PKey .. 'Data' , Data)
end)
if Sucsess then
print('Data is saved')
else
warn('There was an error saving player data: ' .. err)
end
end)
here's the local script:
--ApplyData
game.ReplicatedStorage.Dataloaded.OnClientEvent(function()
--Flash Enabled
if game.ReplicatedStorage.Data.Perm.FlashingEnabled.Value == 0 then
Options.Window.EPOff.TextColor3 = Color3.fromRGB(255,255,255)
Options.Window.EPOff.BackgroundColor3 = Color3.fromRGB(0,0,0)
Options.Window.EPOn.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.EPOn.BackgroundColor3 = Color3.fromRGB(255,255,255)
else
Options.Window.EPOn.TextColor3 = Color3.fromRGB(255,255,255)
Options.Window.EPOn.BackgroundColor3 = Color3.fromRGB(0,0,0)
Options.Window.EPOff.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.EPOff.BackgroundColor3 = Color3.fromRGB(255,255,255)
end
--Difficulty
if game.ReplicatedStorage.Data.Perm.Difficulty.Value == 1 then
Options.Window.Easy.TextColor3 = Color3.fromRGB(255,255,255)
Options.Window.Easy.BackgroundColor3 = Color3.fromRGB(0,0,0)
Options.Window.Normal.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Normal.BackgroundColor3 = Color3.fromRGB(255,255,255)
Options.Window.Hard.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Hard.BackgroundColor3 = Color3.fromRGB(255,255,255)
elseif game.ReplicatedStorage.Data.Perm.Difficulty.Value == 2 then
Options.Window.Normal.TextColor3 = Color3.fromRGB(255,255,255)
Options.Window.Normal.BackgroundColor3 = Color3.fromRGB(0,0,0)
Options.Window.Easy.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Easy.BackgroundColor3 = Color3.fromRGB(255,255,255)
Options.Window.Hard.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Hard.BackgroundColor3 = Color3.fromRGB(255,255,255)
elseif game.ReplicatedStorage.Data.Perm.Difficulty.Value == 2 then
Options.Window.Hard.TextColor3 = Color3.fromRGB(255,255,255)
Options.Window.Hard.BackgroundColor3 = Color3.fromRGB(0,0,0)
Options.Window.Normal.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Normal.BackgroundColor3 = Color3.fromRGB(255,255,255)
Options.Window.Easy.TextColor3 = Color3.fromRGB(0,0,0)
Options.Window.Easy.BackgroundColor3 = Color3.fromRGB(255,255,255)
end
end)

3 comments
Are the values being set client side or server side?
they are set client-sided via the local script, but they should be changing in both the server and client sense they are in replicated storage
ok just did some testing and aperently even though its being changed in replicated storage the data isent being set acording to the server, so i guess at this point i want to know how to send data in and out of the server