Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
3
Answered by 8 years ago

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.

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". Link150 1355 — 8y
0
10 points to griffindor. User#6546 35 — 8y
Ad

Answer this question