Remote events not doing anything

Okay so I want this thing to happen only to the player that triggered it obviously
The problem being nothing is happening, no errors or anything it just doesn’t do anything
The local script that fires the remote event is triggered by click detector and I don’t know if that could be the problem but in my listener code once it sees that the remote event is fired it makes a part visible and prints and it does neither, not sure what the problem is since again its not telling me the problem. Any advice is helpful!

local clickDetector = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
function onMouseClick()
ReplicatedStorage.RemoteEvent:FireServer()
end


clickDetector.MouseClick:connect(onMouseClick)
local TriggerSwitch = game.Workspace:WaitForChild("TriggerSwitch")
local Lever = game.workspace:WaitForChild("Lever")

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
TriggerSwitch.ClickDetector:Destroy()
Lever.Transparency = 0
print("Script did done did")
end)

You can use the ‘MouseClick’ event directly from the server.

4 Likes

I can? How do I go about doing that?

Example of code:

local clickDetector = game -- Replace with ClickDetector reference

function onMouseClick(player)
	-- Code you want to run when the ClickDetector is triggerd
end


clickDetector.MouseClick:connect(onMouseClick)

You dont need remote events in this situation (like @5P3C1A1_XD said above). You can do everything on a server script, no local script is needed at all. Remove the local script from the clickdetector, and add in a server script instead (in the clickdetector), and remove the script that (I assume) is in ServerScriptService.
Then you want to handle everything in that script inside the clickdetector
Code:

local clickDetector = script.Parent
local Lever = game.Workspace:WaitForChild("Lever")
local TriggerSwitch = game.Workspace:WaitForChild("TriggerSwitch")

clickDetector.MouseClick:Connect(function()
   Lever.Transparency = 0
   TriggerSwitch.ClickDetector:Destroy()
end)

And that’ll make the events the switch triggers only
happen for the player that triggers it?

You mean like, if a player triggers the event, only that specific player will see the changes? Is that what you are trying to say? Sorry I couldnt understand what you meant

Seeing as you use :FireServer(), I am assuming that the script that uses the .MouseClick event, is a LocalScript. This is the reason your script isn’t working. Since the click detector is the parent of the script, I’d assume that the LocalScript is in the workspace. If I remember correctly, LocalScripts will only run in PlayerGui, the Character, PlayerScripts and Backpack. As the other people in this thread have said, you don’t even need the RemoteEvent, as you can connect the MouseClick event on the server. If you put a script in the ClickDetector, and put this in the script, it should work:

local clickDetector = script.Parent

local TriggerSwitch = game.Workspace:WaitForChild("TriggerSwitch")
local Lever = game.workspace:WaitForChild("Lever")

clickDetector.MouseClick:Connect(function()
    TriggerSwitch.ClickDetector:Destroy()
    Lever.Transparency = 0
    print("Script did done did")
end)

You can read more about LocalScripts and other characteristics they have below:

LocalScripts

I hope this helps!

1 Like

Yeah thats what I mean, Kinda like a horror game thing but that would be getting off topic

Everyone in the server would be seeing the changes, not only the person who triggered the event.
You want the player who triggered the event to see changes only?

Yes I only want the person who triggered the switch to have the changes

1 Like

Make all the changes in a local script then, don’t use a remote event. Their purpose is to replicate from client

Hmm ok. Then you do need to use a remote event for this. Since you cant use a local script to detect the MouseClick event, and you only want to have the player who triggered the event, you want to fire the remote event to the client. To do that, you want to use the FireClient() method. So you would do RemotEvent:FireClient(player) (example) right under the MouseClick event. And then you do the rest on a local script

Alright I tried and I get this error for the script that fires the event. It says: “FireClient: player argument must be a player object” if I don’t include the player argument it says missing argument

1 Like

Well Im pretty sure thats because you never mentioned player in your script. To get the player, you want to add player in the parenthesis of the MouseClick event, as the first argument.

It should look like this:

clickDetector.MouseClick:Connect(function(player) -- right in here
   RemoteEvent:FireClient(player) -- and then you add 'player' in these parenthesis
end)

Alright really close to getting this, dumb question but with the new clickDetector connect function what do I put as like the clickDetector.MouseClick:connect(onMouseClick) after the script, the example I just gave has a red squiggle under it at the onMouseClick part

wait could you show your current code (in your server script)? Give the code, and show a screenshot of the code in studio

Here it is in a code block

local clickDetector = script.Parent.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
clickDetector.MouseClick:Connect(function(player)
ReplicatedStorage.RemoteEvent:FireClient(player)
end)


clickDetector.MouseClick:connect(onMouseClick)

and a screenshot!
Screenshot_74|517x126

You dont need this line because you already made a function before. Remove this line and you will be good to go

Removed it and we’re back to square 1 of it doing nothing and not giving any error messages