If that doesn’t work, I’d recommend checking out ProfileService, which allows you to store a profile to each user with all their data. (Just look it up in the devforums or watch a youtube tutorial)
I added a table to my updated script, and it seems to work except for it saying in the output that player hasn’t saved yet.
Just in case, here is my updated server script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local lightingSettings = {}
local remoteEvent = ReplicatedStorage.RemoteEvent
local remoteFunction = ReplicatedStorage.RemoteFunction
Players.PlayerAdded:Connect(function(player)
local playerSettings = lightingSettings[player.UserId]
if playerSettings then
print(playerSettings)
remoteEvent:FireClient(player, playerSettings)
else
print("Player " .. player.UserId .. " hasn't saved yet")
end
end)
remoteFunction.OnServerInvoke = function(player, propertyName, value)
if type(propertyName) == "string" then
if not lightingSettings[player.UserId] then
lightingSettings[player.UserId] = {}
end
lightingSettings[player.UserId][propertyName] = value
return true
else
return false, '"propertyName" must be a string value'
end
end
I tried adding a table to the server script, and the only thing that doesn’t work is saving. It’s giving me a message in the output saying Player 1206175753 hasn’t saved yet.
Here is the updated server script with the table:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local lightingSettings = {}
local remoteEvent = ReplicatedStorage.RemoteEvent
local remoteFunction = ReplicatedStorage.RemoteFunction
Players.PlayerAdded:Connect(function(player)
local playerSettings = lightingSettings[player.UserId]
if playerSettings then
print(playerSettings)
remoteEvent:FireClient(player, playerSettings)
else
print("Player " .. player.UserId .. " hasn't saved yet")
end
end)
remoteFunction.OnServerInvoke = function(player, propertyName, value)
if type(propertyName) == "string" then
if not lightingSettings[player.UserId] then
lightingSettings[player.UserId] = {}
end
lightingSettings[player.UserId][propertyName] = value
return true
else
return false, '"propertyName" must be a string value'
end
end
I’m noticing that the script is significantly different than the one I made in the place file
I won’t be able to help you fix the issue if you modify the code I give you
I still have the original code you gave me, I just disabled it and tried the method that task_cancel recommended.
As I said above, I am getting an error saying Brightness is not a valid member of ReplicatedStorage “Replicated Storage”
I think the method that task_cancel recomended was meant to be this:
DataStore:SetAsync(key, {
a = 123,
b = true,
c = "Hello"
})
Instead of trying to Stringifying the Object via HttpService:JSONEncode
and saving it with Datastore:SetAsync
@jasper53682 I shouldn’t code when it’s getting late
That error is happening because of a dumb mistake I made with the LocalScript, I accidentally wrote:
local Lighting = game:GetService("ReplicatedStorage")
instead of:
local Lighting = game:GetService("Lighting")
I learnt my lesson though: I’ll do my best to postpone helping people when I’m getting sleepy, since I don’t want to provide bad code to people
Alright, I’ve created an example for you. You should see a script in ServerStorage
and a localscript in StarterGui
.
LightingSettingsDataStoreExample.rbxl (55.7 KB)
@ExpiredBreaad This seems to work without any errors. However, it doesn’t seem to update itself whenever a setting is changed. How I would I fix this?
Oh, the place i gave you was an example. If you wanted to update the settings from the client, you’d have to call this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SaveLightingSettings = ReplicatedStorage:WaitForChild("SaveLightingSettings")
SaveLightingSettings:InvokeServer(
1, -- birghtness
2, -- saturation
3, -- contrast
true -- shadows
)
Basically pulled from the localscript
in the example i provided
I replaced the local script in StarterGUI with this script, but it still doesn’t detect changes and save them.
could i see your current localscript?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SaveLightingSettings = ReplicatedStorage:WaitForChild("SaveLightingSettings")
SaveLightingSettings:InvokeServer(
1, -- brightness
2, -- saturation
3, -- contrast
true -- shadows
)
I am noticing that it also saves the data, but doesn’t load the last save.
I mean this localscript is just setting the brightness, saturation, contrast, and shadows always to 1, 2, 3, true when you join the game. I’ll try to help you more when i come home, or if someone else could
You’re saving the settings after the player changes them, not just on join, right? If so, do this in a server script:
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.SaveLightingSettings.OnServerInvoke = function(player, brightness, saturation, contrast, shadows)
DataStoreService:SetAsync(player.UserId, {Brightness = brightness, Saturation = saturation, Contrast = contrast, Shadows = shadows})
--wrap this in a pcall to catch errors, also be sure to check if brightness, saturation, contrast, and shadows are right type using type() and make sure they're in the valid number range too
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.