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

why is my script completely ignoring these conditions?

Asked by 5 years ago

I have a function where you click a sight attachment, and it attaches to your gun. However, the statements at lines 18 and 28 do not work, but do not create any errors. It seems like they are completely ignored. Is there a way to fix this or is there some sort of limit to how many conditions can be used in a function?

attachments.Mini.Click:FindFirstChild("ClickDetector").MouseClick:connect(function()
    local attpoint = self.current:FindFirstChild("optic")
    local handle = self.current:FindFirstChild("Handle")
    local origin = self.current:FindFirstChild("HandleOrigin")
    if interaction == true and attpoint.Mini.Value == true then
        deleteFrame()
    if currentoptic == nil then
        Mini()  
    elseif currentoptic ~= nil and currentoptic ~= Mini then
        currentoptic:Destroy()
        RISoff()
        handle.Position = origin.Position
        currentoptic = nil
        attpoint:FindFirstChild("Motor6D"):Destroy()
        self.config.aimFOV       = 70
        self.config.zoomScale    = 1
        Mini()
    elseif currentoptic == Mini then
        currentoptic:Destroy()
        RISoff()
        handle.Position = origin.Position
        currentoptic = nil
        attpoint:FindFirstChild("Motor6D"):Destroy()
        self.config.aimFOV       = 70
        self.config.zoomScale    = 1
    end

    if self.current:FindFirstChild("Iron Sights") then
            local children = self.current:FindFirstChild("Iron Sights"):GetChildren()
            for i = 1,#children do
                children[i].Transparency = 0
            end     
        end
    end
end)

2 answers

Log in to vote
1
Answered by 5 years ago

I resolved the issue by giving the function Mini() and the variable Mini different names, since currentoptic == Mini was confusing Mini() and Mini without giving an error.

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Your indentation is off, misrepresenting the blocks in your conditional statements. Here it is properly indented.

attachments.Mini.Click:FindFirstChild("ClickDetector").MouseClick:connect(function()
    local attpoint = self.current:FindFirstChild("optic")
    local handle = self.current:FindFirstChild("Handle")
    local origin = self.current:FindFirstChild("HandleOrigin")
    if interaction == true and attpoint.Mini.Value == true then
        deleteFrame()
        if currentoptic == nil then
            Mini()
        elseif currentoptic ~= nil and currentoptic ~= Mini then
            currentoptic:Destroy()
            RISoff()
            handle.Position = origin.Position
            currentoptic = nil
            attpoint:FindFirstChild("Motor6D"):Destroy()
            self.config.aimFOV = 70
            self.config.zoomScale = 1
            Mini()
        elseif currentoptic == Mini then
            currentoptic:Destroy()
            RISoff()
            handle.Position = origin.Position
            currentoptic = nil
            attpoint:FindFirstChild("Motor6D"):Destroy()
            self.config.aimFOV = 70
            self.config.zoomScale = 1
        end

        if self.current:FindFirstChild("Iron Sights") then
            local children = self.current:FindFirstChild("Iron Sights"):GetChildren()
            for i = 1, #children do
                children[i].Transparency = 0
            end
        end
    end
end)

Is the above structured how you expected? If not, you might have misplaced an end somewhere.

1
anytime your if statements do not work, make sure your ends are correct and the variables you are comparing mean what you think they mean. ForeverBrown 356 — 5y

Answer this question