I'm trying to fire an event from a GUI when a player clicks a button. The script works, the only problem is i get the output "FireClient can only be called from the server". The part of the script that fires the event looks like this:
local event = Instance.new("RemoteEvent") event.Parent = game.Players.LocalPlayer.PlayerGui event.Name = "Intro" event:FireClient(plr)
Is there any way to fire an event from the client without getting this error?
You should use :FireClient(player) when you are in a server script, attempting to communicate with the client.
For communication with the server, started by the client you need to use :FireServer(). By default the first argument will be the player (which can be a bit confusing at first - essentially anything in the parentheses will be the 2nd argument to the server and so on)
local event = Instance.new("RemoteEvent") event.Parent = game.Players.LocalPlayer.PlayerGui event.Name = "Intro" event:FireServer() -- you'd need this... but it isn't quite that simple.
Also, as far as I am aware you cannot use a RemoteEvent inside PlayerGui; this is because the server can't see the player with Filtering enabled. If you aren't using filtering then this wouldn't be an issue, but your server script that handles calls to these events would need to point to each player (you'd need a .OnServerEvent for each players "Intro" event)
To avoid this; you should create your event in the Workspace (if you're using filtering you need to do this in a server script which can get a bit messy), or create the event manually in ReplicatedStorage before hand.
In my games I have a folder called "RemoteEvents" which I manually add events to in Studio and then call with
game.ReplicatedStorage.RemoteEvents.NameOfMyEvent:FireServer()
This way all players can access the same event and your server code only needs to be listening for one RemoteEvent.
I hope this helped!