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

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

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

2 comments

0

Can you please take a picture of the hierarchy?

0

Yup, see my edit.

2 answers

✓ Accepted answer

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 :)

10 comments

0

Defining a is quite unnecessary, well at least for me.

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".

0

This one I edited should print 1.

0

Thanks, I don't get it though, why won't using my method work? 

0

I fixed it.

0

The value says 0, what it prints goes up by 1 however.

0

Updated Again to see if it works.

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?

0

Lol, idk.\

0

How is it in the negatives..

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)

2 comments

0

Yeah but I would like it to use the value. The value always say 0 still.

0

Whoever down voted me is a troll...

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