I am currently making a loading screen for my new game, and I’m having it load the players data before they actually get into the game. The data manager is a server script, and the loading script is a local script. Does anyone know how to do this?
I think that it will be better to get data when player joins the game and save it when player leaves it.
-- services and folders --
local plrs = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local sss = game:GetService("ServerScriptService")
--
local function SaveData(id)
-- write here
end
local function GetData(id)
-- write here
end
plrs.PlayerAdded:Connect(function(plr)
local data = GetData(plr.UserId) -- call your function here to get plr data
if data["banned"] == true then
plr:Kick()
end
print("New player joined",plr.Name,plr.UserId)
end)
plrs.PlayerRemoving:Connect(function(plr)
SaveData(plr.UserId) -- save plr data
end)
game:BindToClose(function()
for i,plr in plrs:GetPlayers() do
SaveData(plr.UserId) -- save plr data
end
end)