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

i dont understand what return end means. can anyone explain?

Asked by 3 years ago

Hey guys! so recently i watched a sword script tutorial heres the script btw

local tool = script.Parent

local function onTouch(hit)
    local human = hit.Parent:FindFirstChild('Humanoid')
    if not human then return end
    if human.Parent == tool then return end

    human:TakeDamage(20)
end



tool.Handle.Touched:Connect(onTouch)

so the thing is i dont understand what return end means can anyone explain?

1 answer

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago
local tool = script.Parent

local function onTouch(hit)
    local human = hit.Parent:FindFirstChild('Humanoid')
    if not human then 
    return --stops the function from running
    end
    if human.Parent == tool then 
    return --this stops the function from running too 
    end

    human:TakeDamage(20)
end



tool.Handle.Touched:Connect(onTouch)

You can also return values. Here's a link about it. https://education.roblox.com/en-us/resources/returning-values-from-functions

Ad

Answer this question