i have a local script that fires to the server 2 values, OnValue that is an attribute, and the Button that has been pressed, how can i data store the attribute when the player leaves and load them when they join?
heres my script so far
local dataStoreService = game:GetService("DataStoreService")
local settingsdata = dataStoreService:GetDataStore("SettingsData")
local datastoserver = game.ReplicatedStorage.DatasToServerRM
local player = game.Players
datastoserver.OnServerEvent:Connect(function(pler, OnValue, Button)
player.PlayerAdded:Connect(function(plr)
local userid = plr.UserId
local data
local success,errormessage = pcall(function()
print(Button.Name, OnValue)
data = settingsdata:GetAsync(userid)
end)
if success then
Button:SetAttribute("On", data)
print("Settings Loaded Successfully")
else
warn(errormessage)
Button:SetAttribute("On", true)
end
end)
player.PlayerRemoving:Connect(function(plr)
local userid = plr.UserId
local success, errormessage = pcall(function()
settingsdata:SetAsync(userid, Button:GetAttribute("On"))
end)
if success then
print("Settings Saved Successfully")
else
warn(errormessage)
end
end)
end)