Pretty straight forward, simple yet I don’t understand whats going on here:
plrs.PlayerRemoving:Connect(function(plr2)
if plr2.UserId == plr.UserId then
local settingsFolder = plr.Settings
local settingsArray = {}
for _, setting in pairs(settingsFolder:GetChildren()) do
settingsArray[#settingsArray+1] = {setting.Name, setting.Value}
end
print(settingsArray)
settingsRemote:InvokeServer(false, settingsArray)
print("invoked..")
end
end)
invoked… is not being printed
Also I’m using this for saving settings and loading settings so the player doesn’t have to change their settings in-game everytime they rejoin.
local plrs = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local hammers = rs:WaitForChild("Hammers")
local settingsRemote = rs:WaitForChild("Settings")
local dss = game:GetService("DataStoreService")
local settingsData = dss:GetDataStore("Settings")
local statistics = dss:GetDataStore("Stats")
settingsRemote.OnServerInvoke = function(plr, get, settingsToSave)
local plrId = plr.UserId
print(get)
if settingsToSave then
print(settingsToSave)
end
if not get and settingsToSave then
local s, r = pcall(function()
if typeof(settingsToSave) == "table" and #settingsToSave > 0 then
settingsData:SetAsync(plrId, settingsToSave)
end
end)
if not s and r then
print(r)
end
elseif get and not settingsToSave then
return settingsData:GetAsync(plr.UserId)
end
end
I’m not sure in what case it’s needed to fire any remotes upon player disconnection, especially invoking from the client. I would think once the player hits that leave button, Roblox disconnects any/all connections corresponding to the game, and their code.
However, while I trying to get this to happen in my case, I couldn’t get any RemoteEvents or RemoteFunctions to fire from the Client to the Server upon Player Disconnection.
Have you considered syncing the Player’s settings after they change them? Such as firing a RemoteEvent when they hit Save?