Calling a server script function with a local script

Hello everyone! :wave:

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)

You need to use a RemoteEvent to do this. RemoteEvents allow the Server and Clients send data between each other.

More documentation: Remote Events and Callbacks | Documentation - Roblox Creator Hub

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.