Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to use ClickDetectors with FilteringEnabled?

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

✓ Accepted answer

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.

1 comment

0

Hi FRIEND :D It's me, Acheo.

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

4 comments

0

and you can't destroy the player, you have to target the character. so do plr.Character:Destroy()

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.

0

@Bloxy, are you dumb? You can absolutely destroy a player. It was there as an example.

0

@Bloxy this is the best answer yet dont know where these haters came from

This discussion is preserved as it was. New answers, comments, and votes are closed.