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

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

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

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

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