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

How Do I Fix This FilteringEnabled Click Script?

I put a regular script inside a part with a click detector. Here is the script:

function onClicked(plr)
	game.ServerStorage.Ticket:Clone().Parent = plr.Backpack
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

In FilteringEnabled, this doesn't happen. No errors are in the console or ouptut. Please help!

1 answer

✓ Accepted answer

If you use ClickDetectors with FE, you have to filter the clicks through a LocalScript. Try creating a LocalScript and putting it somewhere where that they run (PlayerGui, StarterPlayerScripts, etc.):

Client:

local pathToPart = workspace.Part --// Or wherever the part is.
local clickEvent = workspace:WaitForChild("RemoteEvent")
function onClicked()
	clickEvent:FireServer()
end

pathToPart.ClickDetector.MouseClick:connect(onClicked)

Server:

local clickEvent = Instance.new("RemoteEvent", workspace)
clickEvent.OnServerEvent:connect(function(plr)
	game.ServerStorage.Ticket:Clone().Parent = plr.Backpack
end)

Hope this helped.

EDIT: For multiple parts, you could just do this:

Client:

local parts = {
	workspace.Part,
	workspace.OtherPart,
	workspace.YetAnotherPart,
}
local clickEvent = workspace:WaitForChild("RemoteEvent") --// And no, it doesn't have to be in workspace, just make sure this matches the one that was created in the server script.
for _, part in pairs (parts) do
	if not part:FindFirstChild("ClickDetector") then Instance.new("ClickDetector", part).Name = "ClickDetector" end
	part.ClickDetector.MouseClick:connect(function()
		clickEvent:FireServer(part) --// The argument being the part that was clicked.
	end)
end

Server:

local clickEvent = Instance.new("RemoteEvent", workspace) --// Create the RemoteEvent.
clickEvent.OnServerEvent:connect(function(player, partClicked)
	game.ServerStorage.Ticket:Clone().Parent = player.Backpack
	if partClicked.Name == "YetAnotherPart" then --// Example of handling different parts differently.
		print('A specific part was clicked! Woah!')
	end
end)

Hope this helped to clear some stuff up.

7 comments

0

Do I have to put the RemoteEvent in Workspace? Or can it be anywhere? I'm fairly new to Events and Functions

1

Here is a example for the API http://wiki.roblox.com/index.php?title=Security See title :- How to invoke server specific functions from the client

0

Thanks :)

0

Also, what if I have multiple of these clicked items, then how do I get all of them?

0

Put them in a table and connect the event to all of them with a loop.

0

How would you do the loop? I'm sorry, I am really stupid at this lol

0

Edited.

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