I am trying to use OnClientEvent and FireClient, but it keeps popping up with errors. One of which is (OnClientEvent can only be used on the client) and (FireClient can only be called from the server). I am using a RemoteEvent. It seems to work when I replace FireClient with FireServer and replacing OnClientEvent with OnServerEvent. Here are some pictures.
Its still extremely confusing, and I have been trying to work it out using RemoteEvent | Documentation - Roblox Creator Hub
but it is still very confusing. Ive used both OnClientEvent and FireClient at the same time but it still pops up with an error saying âOnClientEvent can only be used on the clientâ
âCan only be used on the clientâ means that it can only be used in a LocalScript, not in a regular script. Local scripts only run on the client as descendants of certain objects, such as the PlayerGui.
This article explains the difference between clients, servers, and talks about client-server communication:
This reference page gives more information about LocalScripts then I gave in this post:
I switched it to a LocalScript, and now its even more broken. The youtube videos ive watched about this leave it on a Script, and they have no problems. Ive been trying to replicate this, but ive failed.
Put that LocalScript in StarterCharacterScripts and in the Script, instead of âRemote.OnClientEvent:Connect(player)â do âRemote.OnServerEvent:Connect(player)â.
In roblox there is a Server and a Client. A server is the actual game server and the client is the actual player.
A script cannot listen to OnClientEvent because it is not the player, instead, we made this to OnServerEvent. Now, to make that function fire on the script, we will need to use Remote:FireServer(arguments) in a local script.
You fire the RemoteEvent from the server using RemoteEvent:FireClient(player, ...) and in a local script running on the client, you can use RemoteEvent.OnClientEvent:Connect(function). ... are the arguments you wish to send to the client. If you want the client to send info to the server, use :FireServer and .OnServerEvent