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

why is my script completely ignoring these conditions?

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

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.

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 comment

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.

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