Connecting Server-side and client-side input into same event?

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.

image
image

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”)

1 Like

Is “msg” achieved with the .Chatted function?

Yes, I have it connected to Roblox’s default chat system.
image

So what exactly are you trying to solve, you have your server sided input, which is the chat system aka your command.

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

You use :FireServer() which can be received with .OnServerEvent(), you did this correctly right?

You said that the event fires as it should, but I do not see your direct scripting issue.

To communicate from server to client, you can use :FireClient()

You can also use .Chatted on the client.

: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.

On the client you can use .Chatted as well.

local player = game.Players.LocalPlayer

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”)

Can I see the error you get in the output?

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.

You use .Chatted on the server, right?

Due to the nature of what I want to do and how RemoteEvents work, I receive this error when attempting to use :FireClient()
image

I’m aware that RemoteEvents are client, but I need a method to connect them both together for dual input methods, and I’m unsure of what to use

And yes, .Chatted is being handled via the server.

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.
image

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)

How would I define player with .Chatted?

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.