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

How to make a function skip? easy fix hmmmmm

Ok made this touch script and I want to know how to make the function skip to end when a sword touched the part and triggers the function ( sorry for bad explaining Idk how else to explain this.)

not the full script

local function onTouched(part)
	if part.Parent.Parent:FindFirstChild("Sword") then  -- if a sword touched the block then
		print("aaa") -- this worked, but how can I make it skip the fucntion 
	end -- ignores the lines below v
	 Player = Players:GetPlayerFromCharacter(part.Parent)
	     if Player and Player.Character then
         if debounce == false then
	     debounce = true
		    Backpack = Player:WaitForChild("Backpack")
		    for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
			Tool:clone().Parent = Backpack
			tofastman = 2
			end
		    end
		end
	end
end

2 answers

✓ Accepted answer

couldn't help but add a few more fixes lol, but the answer to your question is add a return!

local debounce = false
local function onTouched(part)
	if part.Parent.Parent:FindFirstChild("Sword") then
		print("use return to skip!")
		return --right here my dude
	end --couldn't help myself ;)
	local Player = Players:GetPlayerFromCharacter(part.Parent)
	if Player and Player.Character and debounce == false then
		debounce = true
		Backpack = Player:WaitForChild("Backpack")
		for i = 1, #ToolNames do
			local Tool = Storage:FindFirstChild(ToolNames[i])
			if Tool then
				Tool:clone().Parent = Backpack
				tofastman = 2
			end
        end
		wait() --add any time for your debounce!
		debounce = false
    end
end

2 comments

1

Thanks, but the debounce is set to false in a different function. The full script is 50+ lines, this is just a part of the whole script.

0

got it. just making sure, lol.

Returns are very effective in coding because return does the following to: Returns sends back information. Return breaks a code just like the function break, breaks a loop.

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