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

The gui won't click and add the value to the text why?

Asked by
Qiuor 20
8 years ago
while true do
    wait(.01)
if game.Players.LocalPlayer.Character ~= nil then
if script.Parent.Parent.Parent.Parent.Parent.ASN.Value <= 0 then script.Parent.Visible = false 
else script.Parent.Visible = true
end
else return
end

function click()
    script.Parent.Parent.SSN.SSN.Value = script.Parent.Parent.SSN.SSN.Value + 1
    script.Parent.Parent.Parent.Parent.Parent.ASN.Value = script.Parent.Parent.Parent.Parent.Parent.ASN.Value - 1
end
end
script.Parent.MouseButton1Down:connect(click)

So, This is meant to add a number to the number but, it doesn't click, the gui does not work.

script.Parent.MA.Text = script.Parent.MA.MAV.Value
script.Parent.AV.Text = script.Parent.AV.AV.Value
script.Parent.BN.Text = script.Parent.BN.BN.Value
script.Parent.EN.Text = script.Parent.EN.EN.Value
script.Parent.SN.Text = script.Parent.SN.SN.Value
script.Parent.SSN.Text = script.Parent.SSN.SSN.Value
script.Parent.BSN.Text = script.Parent.BSN.BSN.Value
script.Parent.BWSN.Text = script.Parent.BWSN.BWN.Value
script.Parent.AN.Text = script.Parent.AN.AN.Value
script.Parent.GSL.Text = script.Parent.GSL.GSN.Value

it even is connected through here, the values and the text. Why isn't this working?

2
Please use variables for all of those things. At least for script.Parent GoldenPhysics 474 — 8y
0
Why? It is short, not complicated, to write over and over! SH_Helper 61 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

break and return do different things, break exits a loop and continues the code execution where as return stops the code execution and passes back a value. You also have another problem which is the function click only exists inside the loop. Lastly it also helps to tab your code so you can tell when each if statement ends.

Example of the problem (return)

local i = 0
while true do
    i = i + 1
    if i > 5 then print('loop ended') return end
end
print('end')

output:-

loop ended

(break)

local i = 0

while true do
    i = i + 1
    if i > 5 then print('loop ended') break end
end

print('end')

output:-

loop ended

end

I hope this helps

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

There was no point of making a loop since we can use Changed event

You should put the function out of the loop

Your script:

while true do
    wait(.01)
if game.Players.LocalPlayer.Character ~= nil then
if script.Parent.Parent.Parent.Parent.Parent.ASN.Value <= 0 then script.Parent.Visible = false 
else script.Parent.Visible = true
end
else return
end

function click()
    script.Parent.Parent.SSN.SSN.Value = script.Parent.Parent.SSN.SSN.Value + 1
    script.Parent.Parent.Parent.Parent.Parent.ASN.Value = script.Parent.Parent.Parent.Parent.Parent.ASN.Value - 1
end
end
script.Parent.MouseButton1Down:connect(click)

My script (Fixed):

local Player = game.Players.LocalPlayer
local ASN = script.Parent.Parent.Parent.Parent.Parent.ASN
Player.CharacterAdded:connect(function()
if Player.Character ~= nil then
if ASN.Value <= 0 then script.Parent.Visible = false 
else script.Parent.Visible = true
end
end
end)

ASN.Changed:connect(function(newValue)
if newValue <= 0 then script.Parent.Visible = false 
end 
end)


function click()
    script.Parent.Parent.SSN.SSN.Value = script.Parent.Parent.SSN.SSN.Value + 1
    ASN.Value = ASN.Value - 1
end

script.Parent.MouseButton1Down:connect(click)

You can read more about Changed event here http://wiki.roblox.com/index.php?title=API:Class/IntValue/Changed

0
That didn't work, it still doesn't click. Qiuor 20 — 8y
0
It worked for me. Output says noting? Vinteriss 10 — 8y

Answer this question