I have some models in Workspace and I want a local script to create a OnClick event for all the parts that use ClickDetectors. I made a loop function but I'm having a hard time figuring out how to relate the event to the current part.
for i,v in pairs(game.Workspace.cars:GetChildren()) do
but=v:FindFirstChild("but")
if but then
but.ClickDetector.MouseClick:connect(function(player)
local car=game.Workspace.RemoteEvents:WaitForChild("OwnCar")
local test=car:InvokeServer(but)
end)
end
end
This will allow a person to click a button to own a car but it always sends the last "but" or part from the loop even if they click a different button, any way to get the current part clicked from the event?

1 comment
I didn't know scoping actually did that, thanks!