Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I call a remote event from a line in the server?

I am trying to work a remote event and I want a function from the local script to be activated from my main script. I got an error saying there was a missing argument in the main script, but I think I set it up wrong so I don't think this is the problem anyway. I am trying to make a gui appear on the player's screen but only when triggered by the serverscript.

here's the main script

local guiStart = game:GetService("ReplicatedStorage").TeamGuiStart

guiStart:FireClient()

and the local script

local function teamFrameOn()
    local teamFrame = game.Players.LocalPlayer.PlayerGui.GUI.TeamFrame
    teamFrame.Visible = true
end

Thank you!

1 comment

0

Do accept the answer so we can both iearn some reputation points.

2 answers

✓ Accepted answer

The other answer written here is not correct.

Remote Event do not have a member called FireAllClient. Grammatically, that is an error and Roblox makes no exception on this either. It should be, if you still intend to fire for all Clients, then you would use FireAllClients with the s. It is a fairly small mistake, but in the end, it throws you an error.

FireAllClients does not need an argument because the Remote Event fires for all the connected users. Hence, no need for the Player arguments.

To fire for a single player, you would have to specify a Player argument.

Server Sided Script

-- [Declaration Section]
--\\ Game Services 
local ReplicatedStorage      = game:GetService("ReplicatedStorage");
local Players                = game:GetService("Players");

--\\ Remote Event Location 
local RemoteEvent            = ReplicatedStorage:WaitForChild("RemoteEvent");

-- [Processing Section]

local function Fire_Players (Player)
	RemoteEvent:FireClient(Player);
end;

-- [Connecting Section]
Players.PlayerAdded:Connect(Fire_Players);

Client Sided Script

-- [Declaration Section]
--\\ Game Services 
local ReplicatedStorage      = game:GetService("ReplicatedStorage");

--\\ Remote Event Location 
local RemoteEvent            = ReplicatedStorage:WaitForChild("RemoteEvent");

-- [Processing Section]

local function On_Client_Event ()
	print("HI");
end;

-- [Connecting Section]
RemoteEvent.OnClientEvent:Connect(On_Client_Event);

Do keep in mind that, you do not always have to use Players Service to get the Players. There are also other ways and that can be used as well.

Resources to learn

Replace the guiStart:FireClient() with guiStart:FireAllClient()

If you put guiStart:FireClient() it will only give you an error because you didn't specify the client. But, if you put guiStart:FireAllClient() you don't need to specify the client, because it will fire on all client's.

3 comments

0

If you only wanted to show the gui on a specific player then please tell me.

0

That is incorrect. It should be FireAllClients not FireAllClient

0

kk

This discussion is preserved as it was. New answers, comments, and votes are closed.