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?
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.
Keep it as a server script inside Workspace and you should be fine.