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