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

How do I add another name onTouched function?

Asked by 7 years ago
Edited 7 years ago

How do I add another name onTouched function? I want to add different name on line 6, like skeleton. Thanks!

local debounce = false

function onTouched(hit)
    if not debounce then
        debounce = true
        if hit.Parent.Name:sub(1,17) == "AFK Noob Lv 1 HP " or "Noob" then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
            wait(0.5)
            debounce = false
            elseif hit.Parent.Name:sub(1,4) == "Noob" then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
            wait(0.5)
            debounce = false
        end
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

Add an elseif.

local debounce = false

function onTouched(hit)
    if not debounce then
        debounce = true
        if hit.Parent.Name:sub(1,17) == "AFK Noob Lv 1 HP " then -- I want to add different name here, like skeleton 
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 25
            wait(0.5)
            debounce = false
        elseif hit.Parent.Name:sub(1,8) == "Skeleton" then
        --// Do stuff
        end
    end
end

script.Parent.Touched:connect(onTouched)

There are better ways to go about doing what you're doing, though. Hope this helped.

Ad

Answer this question