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