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

When I press a gui button, why won't it add 1 to a value like I scripted it to?

Asked by
Freemium 110
10 years ago

When a button is pressed in a gui, it is supposed to add 1 to an int value. I've tried both int and number and it won't work, no output errors.

a = script.Parent.Parent.yes

script.Parent.MouseButton1Down:connect(function()
a.Value = a.Value + 1
end)

[Edit] Hierarchy: http://s30.postimg.org/60gz3kfhd/hierarchy.png

0
Can you please take a picture of the hierarchy? AmericanStripes 610 — 10y
0
Yup, see my edit. Freemium 110 — 10y

2 answers

Log in to vote
1
Answered by
HexC3D 830 Moderation Voter
10 years ago

This is an example should work just make a new roblox Text button in the Gui and put this script in the text button and it should print 1.

function click()
a = Instance.new("IntValue")
a.Parent =  game.Workspace
for i = 1, 1  do
a.Value = a.Value + 1
end
print(a.Value)
end
script.Parent.MouseButton1Click:connect(click)


Not to try it the way you wanted

Gui = script.Parent.Parent.Parent
Val = Gui.Frame.Yes
script.Parent.MouseButton1Click:connect(function()
for i = 1,1 do
Val.Value = Val.Value + 1
end
print(Val.Value)
 z = Instance.new("TextLabel")
z.Parent = Gui.Frame
z.Text = ""..Val.Value

end)

It should work :)

0
Defining a is quite unnecessary, well at least for me. HexC3D 830 — 10y
0
It doesn't work, it prints 0 and the value stays 0. I've tried with both IntValue and NumberValue, only thing I changed is "Yes" to "yes" because the name of the value is "yes". Freemium 110 — 10y
0
This one I edited should print 1. HexC3D 830 — 10y
0
Thanks, I don't get it though, why won't using my method work?  Freemium 110 — 10y
View all comments (6 more)
0
I fixed it. HexC3D 830 — 10y
0
The value says 0, what it prints goes up by 1 however. Freemium 110 — 10y
0
Updated Again to see if it works. HexC3D 830 — 10y
0
Thank you, while I was waiting, I did some experimenting and found a weird fix. I changed "Gui = script.Parent.Parent.Parent" to "Gui = game.StarterGui.ScreenGui. Why is that? Freemium 110 — 10y
0
Lol, idk.\ HexC3D 830 — 10y
0
How is it in the negatives.. HexC3D 830 — 10y
Ad
Log in to vote
-2
Answered by
Damo999 182
10 years ago

This is what i did first i created the ScreenGui inside that i put a frame i put an intvalue and a TextButton inside of the frame i then put a script inside of the TextButton and then i used this script.

button = script.Parent -- the textbutton
value = script.Parent.Parent.Value -- the intvalue
value = 0 -- don't really need this 

button.MouseButton1Down:connect(function()
    value = value +1
    print(value)
end)
0
Yeah but I would like it to use the value. The value always say 0 still. Freemium 110 — 10y
0
Whoever down voted me is a troll... Damo999 182 — 10y

Answer this question