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
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
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.