Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to use ClickDetectors with FilteringEnabled?

Asked by 8 years ago

I realized when using filteringenabled and click detectors, it doesn't quite work. I've already attempted swapping the type of script. Here's the code I used:

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    plr:Destroy()
end)

Any ideas or help?

2 answers

Log in to vote
3
Answered by 8 years ago

As the wiki states: "If you have FilteringEnabled set to 'true', this will not fire on the server and only on the client. To avoid this, connect the event on the client and use a RemoteEvent to inform the server about it being clicked."

You can find this source here: http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseClick

Solution

Like every other change that has to be made when FilteringEnabled interferes with something, remotes are the way to go, and that's how you'll solve this.

Remotes

A remote (be it a remote event, remote function, bindable event, ect) are used to passing information between their corresponding sides of the network (except for bindable remotes, which are only used to pass information between the same machine).

If you don't know how remotes work, I HIGHLY suggest going here, reading all about them, and practicing them: http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial

Example

Once you've done that, you'll probably be able to understand this example a little better, implementing the use of a remote event defined with the "Remote" variable:

-- A remote stored inside the ReplicatedStorage, named "ClickEvent". Assuming the remote exists, and a server script has established an event listener for the remote.

-- Keep in mind, this is a local script somewhere inside the player.

-- The remote event
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("ClickEvent")

-- The click detector inside of a part
local Clicker = workspace:WaitForChild("Part"):WaitForChild("ClickDetector")

-- Setting the click event locally
Clicker.MouseClick:connect(function(plr)
    Remote:FireServer() -- Fires the server listener that holds the information. This will also automatically pass the player who clicked the detector, to the event listener.
end)

Hope this helped. Let me know if you have any questions.

0
Hi FRIEND :D It's me, Acheo. RevergeHelps 63 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Keep it as a server script inside Workspace and you should be fine.

0
and you can't destroy the player, you have to target the character. so do plr.Character:Destroy() BloxyFists 0 — 8y
0
Not only is this barely an answer, but this is not a solution. If you read the information on the wiki, you'd see this would fail using FilteringEnabled. How2Script 105 — 8y
0
@Bloxy, are you dumb? You can absolutely destroy a player. It was there as an example. RevergeHelps 63 — 8y
0
@Bloxy this is the best answer yet dont know where these haters came from tantec 305 — 5y

Answer this question