Communication between Serverscript and localscript

Hello,

I’ve been trying to establish communication between a serverscript and a localscript to prompt the gamepass purchase screen if the player doesn’t own the gamepass, however I got no idea about how to do that. Serverscript checks if the player owns a gamepass or not, and if the player doesn’t own the gamepass then I want the serverscript to somehow communicate with the localscript, so that I can prompt purchase screen. Any help would be much appreciated.

1 Like

You can use Remote Events for Client-Server communication.

I know the usage of remotevents, and I don’t want a client-server communication, I want a server-client communication, if it’s possible.

Remote Events can do both of those things.

Can you give an example, because I’m not really experienced with remote events other than the :FireServer(). I tried using :FireClient(), but I think they work differently.

:FireClient() requires a player argument

So I can do something like:

:FireClient(player, “Args here”)

1 Like

You can do:

FireAllClients(arg1,arg2,arg3,...)

FireClient(Player,arg1,arg2,arg3,...)

1 Like

Yes, you can do that. Here is an example:

--ServerScript
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local CountdownLenght = 60
local Player = game.Players:WaitForChlid("BenMactavsin") --Normally you don't create variable in round countdown but I did for example's sake.
while CountdownLenght > 0 do
	wait(1)
	CountdownLenght -= 1
	RemoteEvent:FireClient(Player, CountdownLenght) --Normally you would use :FireAllClients() in a round countdown like this one but I used :FireClient() for example's sake again.
end

--LocalScript
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Label = script.Parent.Frame.TextLabel
RemoteEvent.OnClientEvent:Connect(function(Counter)
	Label.Text = tostring(Counter)
end)

2 Likes