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

Why won't the value change and print no?

Asked by 6 years ago
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)



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. DinozCreates 1070 — 6y
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" True_Warrior 29 — 6y
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 DinozCreates 1070 — 6y
0
It's supposed to print yes and change the value so next time it will be no, however it's only printing yes True_Warrior 29 — 6y
View all comments (8 more)
0
Have you tried using a bool instead? Ill post an answer DinozCreates 1070 — 6y
0
Yes, but I'd like to see your version of it. True_Warrior 29 — 6y
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. User#19524 175 — 6y
0
I do have to ask why you have checker as a global, is that neccesary or can we make that local? DinozCreates 1070 — 6y
0
Additionally, the script is disabling itself, and cannot re-enable itself. Either don't disable it or have another script enable it. User#19524 175 — 6y
0
How would I go about checking when the mouse is hovering over that object then? True_Warrior 29 — 6y
0
@inca if the script isn't able to re-enable itself how is it printing out 'yes' thats called after the disable? DinozCreates 1070 — 6y
0
It doesn't. User#19524 175 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
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)

0
 No explanation was given whatsoever. User#19524 175 — 6y
0
Did you not see me discussing this with him in the comments?.... DinozCreates 1070 — 6y
0
Explain it in the answer as well. User#19524 175 — 6y
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 True_Warrior 29 — 6y
0
Sorry, i was just trying to show him what i was saying, its hard to do without posting the editted code. DinozCreates 1070 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question