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

How do I add another name onTouched function?

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 comment

1 answer

✓ Accepted answer

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.

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