Hello, I’m trying to create a script that allows me to use a client input to fire a RemoteEvent but also use a server-side input that can fire this same event.
My remote event works perfectly, but I don’t know how to go about a server-side input. Obviously this section of my code doesn’t work, as it’s trying to fire a RemoteEvent via server input.
For context, the client-side script is when a player is sitting down in a vehicle. The server-side is when a specific player chats a message/command (In this case, “Roadrunner lower/lift” or “cars lower/lift”)
I’m trying to get the server to connect to this event that the client uses, so that I can either have user input or server input.
In a scenario:
I sit in the vehicle and press one of the input keys, the event fires as normal and connects to the server. However, I step out of the vehicle and use my chat commands. The event fires as it should.
I’m wanting this option so that I can fill and release the airbags on my vehicle while driving it or while standing outside of it, as it’s a show car that I plan on using in car shows
:FireServer() works as it should, the client-side input works perfectly.
I’m trying to get the chat commands to fire this same event, though. I tried using :FireClient() but I got an error spit out at me.
player.Chatted:Connect(function(msg)
–you can then fire to the server from the client with if-statements using msg
end)
You can only use FireServer() on the client, instead of firing to the event, you can just put the function there directly without using any remote events if your on the server already.
The problem with setting .Chatted as a client is I’d need to set several server functions over to RemoteEvent functions and connect them all.
On top of this, I don’t know how I would get my vehicle’s personal chat system to work, as it actually connects itself to the chat system to speak on some specific commands (Such as when using Ping, the vehicle will respond in-chat with “Pong”)
You can only use FireServer() on the client, instead of firing to the event, you can just put the function there directly without using any remote events if your on the server already.
The whole reason for this in the first place was to get rid of this. I have a somewhat bulky function that I want the client to handle instead to take load off of the server. I originally ran one large function with the chat commands itself and connected the client to that, but the server took the function, making clients only an input method and not a handler.
Can I see the line of code in which you use FireClient? Also why are you handling air bags on the client via the chat system, when on key binds you are handling air bags on the server?
You have this in the incorrect order.
.Chatted is being handled via the server, the entire chat commands thing is.
The air bags are being handled by the client with input with a RemoteEvent connecting the client to the server.
My original method had the client input just be handled itself and my entire function be handled by the server. I want the server to only give input and receive the final outcome, I want the client to handle the actual function; which is why I want dual inputs from both the server and client.
The only purpose .Chatted is serving is to read a chat command. Everything else is handled in separate functions over 200 lines long for the multiple commands I have.
When the client receives the event via chat commands, you could just FireServer with the data given again for command handling. I would like to see a screenshot of the line that you use FireClient.
How would I go about this? Would the client receive the chat input and then fire the event itself?
And currently FireClient is bound to the chat commands. I know little about FilteringEnabled, as my coding knowledge dates it.
FireClient() requires the first parameter to be a player object, the client that you are giving the information to.
Usage: event:FireClient(player,“BagsLift”,true)
event.OnClientEvent:Connect(function(bag,bool)
event:FireServer(bag,bool) --Sending information given to client from server, to server again for command registration
end)
I would go about this by adding a PlayerAdded function with the player argument (player being added) and then using player.Chatted(msg) which would give you a player object
If you wanted only specific users to be able to use a command, you will need a if statement in the .Chatted event, checking for player username before command registration and handling.