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

Why won't the value change and print no?

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Mirror = game.Workspace:WaitForChild('Mirror')
local MirrorGui = player.PlayerGui.MirrorGui
local GuiLabel = MirrorGui.TextLabel
checker = 0

game:GetService('RunService').RenderStepped:Connect(function()
	local X = Mouse.X
	local Y = Mouse.Y
	
	if Mouse.Target and Mouse.Target.Name == 'Mirror' then
		MirrorGui.Enabled = true
		GuiLabel.Position = UDim2.new(0,X,0,Y)
			Mouse.Button1Down:Connect(function()
				script.Disabled = true
				wait(.01)
				script.Disabled = false
					if checker == 0 then
						wait(.01)
						print('yes')
						checker = 1
					elseif checker == 1 then 
						wait(.01)
						print('no')
						checker = 0
					
				end
				
			end)
		
	else
		MirrorGui.Enabled = false
	end
end)



12 comments

0

My understanding of elseif is that it will only run if the if is not true. So you would just get rid of line 23. Probably wrong though. Or I guess you could change the elseif to another if, and that would run both.

0

I'm attempting to make it to where I click it once, It print yes and then if I click it again it prints no and those are alternating. If I get rid of the elseif, it will just run "yes no"

0

I misunderstood what you were doing then. Is the initial if statement printing 'yes', and changing the value? Or is it printing yes and not changing the value

0

It's supposed to print yes and change the value so next time it will be no, however it's only printing yes

0

Have you tried using a bool instead? Ill post an answer

0

Yes, but I'd like to see your version of it.

0

I do have to ask why you have checker as a global, is that neccesary or can we make that local?

0

You shouldn't nest the Button1Down event inside a RenderStepped, you'll be creating a connection for that event every frame or so, so multiple functions are called.

0

Additionally, the script is disabling itself, and cannot re-enable itself. Either don't disable it or have another script enable it.

0

How would I go about checking when the mouse is hovering over that object then?

0

@inca if the script isn't able to re-enable itself how is it printing out 'yes' thats called after the disable?

0

It doesn't.

2 answers

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local Mirror = game.Workspace:WaitForChild('Mirror')
local MirrorGui = player.PlayerGui.MirrorGui
local GuiLabel = MirrorGui.TextLabel
checker = false

game:GetService('RunService').RenderStepped:Connect(function()
    local X = Mouse.X
    local Y = Mouse.Y

    if Mouse.Target and Mouse.Target.Name == 'Mirror' then
        MirrorGui.Enabled = true
        GuiLabel.Position = UDim2.new(0,X,0,Y)
            Mouse.Button1Down:Connect(function()
                script.Disabled = true
                wait(.01)
                script.Disabled = false
                    if checker == false then
                        wait(.01)
                        print('yes')
                        checker = true
                    elseif checker == true then 
                        wait(.01)
                        print('no')
                        checker = false

                end

            end)

    else
        MirrorGui.Enabled = false
    end
end)

5 comments

0

 No explanation was given whatsoever.

0

Did you not see me discussing this with him in the comments?....

0

Explain it in the answer as well.

0

Unfortunately it didn't work. I just don't know how I'd go about checking if the mouse is hovering over the object without renderstepped

0

Sorry, i was just trying to show him what i was saying, its hard to do without posting the editted code.

I had to move my onClick function outside the render function so the number of instances produced returned to normal.

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