RemoteEvent Help Needed

Hello! I’m trying to fire an event to a single client when a button is clicked on. I’ve searched the DevForum and the Developer Documents, yet I can’t find anything that works. RemoteEvents is the one thing I can’t seem to learn.

My current script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local remoteEvent = ReplicatedStorage:WaitForChild("Camera")

script.Parent.MouseButton1Click:Connect(function()
	remoteEvent:FireClient()
end)

image

Any and all help would be appreciated!

Swap the Script for a Local Script and see how that changes. Not much else I can help with unless I can see the full object tree.

Still doesn’t work. What would you like to see?

:FireClient needs a Player parameter.

You cant call the MouseButton1Click event on a Server Script. You need to use a local script instead, as what @xZylter said.
Can you also explain more of what you are trying to do? It can help us understand your issue and fix it sooner

If this helps, here. image

somehow, if you enable filtering enabled you still can detect it

Inputs from the client should always be signaled through the client, meaning you should be using a LocalScript, not a Server Script.

With that out of the way, local scripts cannot call :FireClient, that can only be called from the server. You can fire:

remoteEvent:FireServer()

from the client and this will trigger the event on the server with the parameter of the client that triggered the event, in this case, the client that clicked the specified button.

You can hook the remote event on the server by using a server script that hooks up an OnServerEvent event:

On the server:

remoteEvent.OnServerEvent:Connect(function(Player) --the Player that clicked the button from the client
     print(Player)
     --execute here from the server
end)

you need a player parameter as @DalekAndrew99 said

It’s a view stage button: A GUI button is clicked on, the player’s camera is tweened to a part.

What would the player parameter be in this scenario?

Sorry for not picking up on this in my first post, but if you want to send information from the client to the server you have to use :FireServer().

I assume that’s what you’re trying to do because you can’t send information to other players from the client. But you also don’t need to use a RemoteEvent to manage a player’s camera, each client handles their own camera.

I dont think remote events are necessary in this situation then, unless maybe if you want all players’ camera tweened to a part.

@xZylter @BabyNinjaTime What should I use instead of a RemoteEvent then? I’m only trying to move the clicker’s camera, not everyones.

you want to have the tweening code right inside of the MouseButton1Click function.
Also, i suggest you use Button.Activated rather than using Button.MouseButton1Click function.
And also, make sure you remove the server script and use a local script instead, otherwise it wont work.
Here’s an example of what your code should look like:

local Btn = script.Parent

Btn.Activated:Connect(function()
   -- Full Tween Code right in here
end)
1 Like

Thank you so much, it works. Sorry on my part, I have little to no experience with RemoteEvents and when they should be used.

1 Like

No problem, happy to help! And its okay, no need to say sorry at all, everyone is always at a learning stage!

1 Like