Remote Event Question

This may be a very very stupid question, but I can’t figure out how to do it and I can’t find any articles on it. The answer is probably extremely simple, or its not possible what I’m trying to achieve.

I have a RemoteEvent in ReplicatedStorage called “equipevent”

What I’m trying to do is call that event on behalf of a player, from the SSS.
Is that possible?

example:

local equipevent = storage:WaitForChild("equipevent")
equipevent:FireServer(PLAYER, "test") --try to fire event for player

Obviously this isn’t working, which is why I’m here :frowning:

Is there anyway to achieve this?

Only the client can fire the server. The server may fire one client or all clients.

You must fire that remote in the client if your wanting to fire the event to the server, then the event listener must go in the server script. If you are wanting to fire the remote on the client then just do the opposite.

Hello.
If you :FireServer(arguments,arguments,arguments), the first argument will be the player who fired the RemoteEvent.
To fire a client you’ll have to :FireClient(client,arguments,arguments,arguments) or you can :FireAllClients(arguments,arguments,arguments).
Here is an example:

Client

game.ReplicatedStorage.RemoteEvent:FireServer("Hello!")

Server

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, message)
     print(player.Name.. " said: " ..message)
end)

Thank you all for the replys! Means alot!

But maybe I should rephrase my question.

Is there anyway to force a client to fire an event?

So in the reply that @JakyeRU said, would there be anyway to force that player to :FireServer(“Hello!”)?

What do you mean by “force to fire”? If you tell the script to :FireServer(), it will do it (unless an error occurs).

I’m confused by what you’re asking :confused:

So I have an event in RepStorage, and I’m trying to fire that event from a script in ServerScrService, but fire that event on behalf of a player in my game.

Of course. There are many ways. For example, you could make a UI, insert a TextButton and when the button is pressed, you fire the event.

script.Parent.MouseButton1Click:Connect(function()
     game.ReplicatedStorage.RemoteEvent:FireServer("Button pressed.")
end)

Another way would be UserInputService. When a key / certain key is pressed, you can fire the event.

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, box)
     if input.KeyCode == Enum.KeyCode.E and not box then
          game.ReplicatedStorage.RemoteEvent:FireServer("E Pressed!")
     end
end)

Note: The second argument, box, will return true/false if the player is focused in a TextBox, for example the chat. So you won’t fire the event if the player writes something that contain E in the chat. Also, only LocalScripts can Fire the server, only ServerScripts can Fire the client.

I don’t think you understood my question :frowning: I’m really sorry that you wrote all that :confused:

What I’m trying to do is; from the serverscriptservice, make a player :FireServer()

I think I’ll just find a different way to achieve what I’m trying to do :neutral_face:

You cannot :FireServer() from the ServerScriptService. If you want to fire an event from the server, you need to use :FireClient(player).

So you are trying to make a player Fire the server, from the Server?

I am aware of that, but is there anyway to send a parameter through that?

like: event:FireClient(player, “random stuff”)

Yes, you can. event:FireClient(player, "Hello!") will work.

From my understanding, you want to pretend that a player called the remote event, but this is happening from the server, is this correct?

Yes, that is exactly what I’m trying to do. Is it possible??

You could do many things. A bindable event could work, you could also just use a named function.

local function doSomething(player, ...)
	print("Received from", player.Name, ...)
end

remote.OnServerEvent:Connect(doSomething)
doSomething(Players.SomePlayer, "Test call")
1 Like

I tried that but it didn’t work :frowning:

Oooo that should work!

Thank you so much!! :slight_smile:

edit: I knew it would be simple :mad: but my brain is fried lolol