✓ 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
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")
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)
end)
end
Server:
local clickEvent = Instance.new("RemoteEvent", workspace)
clickEvent.OnServerEvent:connect(function(player, partClicked)
game.ServerStorage.Ticket:Clone().Parent = player.Backpack
if partClicked.Name == "YetAnotherPart" then
print('A specific part was clicked! Woah!')
end
end)
Hope this helped to clear some stuff up.
7 comments
Do I have to put the RemoteEvent in Workspace? Or can it be anywhere? I'm fairly new to Events and Functions
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
Thanks :)
Also, what if I have multiple of these clicked items, then how do I get all of them?
Put them in a table and connect the event to all of them with a loop.
How would you do the loop? I'm sorry, I am really stupid at this lol
Edited.