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

What seems to be the problem with the event "Touched"?

I am currently trying to see if I completely understand how the Debounce and seeing if the it's a player who touched the part. But when I run the script, it says attempt to call method 'Touched' (a userdata value)

Here's the code,

function OnTouched(part)
	Debounce = false
	player = part.Parent:FindFirstChild("Humanoid")
	if not player then
		player2 = player.Parent:FindFirstChild("Humanoid")
	end
	if not Debounce then
		Debounce = true
		if player or player2 then
			print("It worked!")
		end
		wait(3)
	end
	Debounce = false
end


script.Parent:Touched(OnTouch)

1 answer

Events

Touched is not a method, as it is an event. In the true nature of events, you need to be using them as events.

The correct line is

script.Parent.Touched:connect(OnTouch)

Remember it, because that mistake is lazy.

2 comments

0

To explain further, you do not call events. You subscribe a function to them using their ":connect()" method. Roblox will call your function back whenever the event triggers. Such a function is known as a "Callback", or a "Listener".

0

10 points to griffindor.

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