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

How to make a function skip? easy fix hmmmmm

Asked by
14dark14 167
4 years ago
Edited 4 years ago

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

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
4 years ago

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
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. 14dark14 167 — 4y
0
got it. just making sure, lol. Mayk728 855 — 4y
Ad
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

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.

Answer this question