Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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!

0
Do accept the answer so we can both iearn some reputation points. Zafirua 1348 — 5y

2 answers

Log in to vote
0
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

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

Ad
Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
If you only wanted to show the gui on a specific player then please tell me. CjayPlyz 643 — 5y
0
That is incorrect. It should be `FireAllClients` not `FireAllClient` Zafirua 1348 — 5y
0
kk CjayPlyz 643 — 5y

Answer this question