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
01local player = game.Players.LocalPlayer
02local Mouse = player:GetMouse()
03local Mirror = game.Workspace:WaitForChild('Mirror')
04local MirrorGui = player.PlayerGui.MirrorGui
05local GuiLabel = MirrorGui.TextLabel
06checker = 0
07 
08game:GetService('RunService').RenderStepped:Connect(function()
09    local X = Mouse.X
10    local Y = Mouse.Y
11 
12    if Mouse.Target and Mouse.Target.Name == 'Mirror' then
13        MirrorGui.Enabled = true
14        GuiLabel.Position = UDim2.new(0,X,0,Y)
15            Mouse.Button1Down:Connect(function()
View all 35 lines...
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
01local player = game.Players.LocalPlayer
02local Mouse = player:GetMouse()
03local Mirror = game.Workspace:WaitForChild('Mirror')
04local MirrorGui = player.PlayerGui.MirrorGui
05local GuiLabel = MirrorGui.TextLabel
06checker = false
07 
08game:GetService('RunService').RenderStepped:Connect(function()
09    local X = Mouse.X
10    local Y = Mouse.Y
11 
12    if Mouse.Target and Mouse.Target.Name == 'Mirror' then
13        MirrorGui.Enabled = true
14        GuiLabel.Position = UDim2.new(0,X,0,Y)
15            Mouse.Button1Down:Connect(function()
View all 35 lines...
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