I can’t provide an exact screenshot of the error, however it pretty much said “Connection could not be made because the thing is not a function”. How can I fix this? I’m passing a function in right?
My other problem is that I’m not sure whether the hit argument is being passed.
Code:
local function touchedFunction(hit,pad)
-- my code
end
-- These are all valid parts
connection = part1.Touched:Connect(touchedFunction(part1)) --Is hit being passed?
connection2 = part3.Touched:Connect(touchedFunction(part2))
connection3 = part3.Touched:Connect(touchedFunction(part3))
Thanks!
Within the first set of parenthesis, there should be your function, i.e votingTouched, not Touched. In addition to this, you don’t need the parenthesis for the function, as they’ll be automatically passed to the function.
Also, Touched only has one parameter, which is hit.
Your code should look like this:
local function votingTouched(hit)
-- my code
end
connection = part1.Touched:Connect(votingTouched)
connection2 = part3.Touched:Connect(votingTouched)
connection3 = part3.Touched:Connect(votingTouched)
@RichardPRoosevelt @Benified4Life
Apologies, I editing my code for the post and accidentally turned votingTouched into touched. In my real code it is running.
@Benified4Life
I need to pass another parameter into the votingTouched function, how could I do that?
Depends what you need to be fired. But, considering in Touched, you can’t exactly fire any other parameters, since it only returns what it’s touching, you’d be better off just sourcing it within the function. What are you trying to do with the second parameter, though?