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

Score Click Gui?

Alright, so here's what I'm trying to do.

Whenever someone would click this certain brick, their 'score' in a GUI I made would go up by 1 each time they click the brick. For some reason, I cannot get this to work.

Also, there's two TextLabels where the score is supposed to show. One is just plain white, the other is just a shadow to make it fancy.

Also, I'd like for the score to first be changed in a NumberValue and then the two TextLabels be equal to whatever the NumberValue is set to. This way, I can use the Data Store later for automatic score saving.

Anyways, here's some screenshots:

ClicksGui Hierarchy: http://prntscr.com/2x6ihd ClicksGui to player script: http://prntscr.com/2x6imt ClicksGui Script: http://prntscr.com/2x6ivl The actual GUI: http://prntscr.com/2x6kvu And last but not least, the brick that changes your score each time you click it: http://prntscr.com/2x6j7i

Hopefully my question (second 'paragraph' from top - it's not structured like a sentence but you know what I mean) is clear and understandable. Thank you in advanced!

1 answer

On this screenshot, not really sure which it is, there doesn't seem to be an actually script in there. That would be the problem.

Unless your question is, how you would go about it. In that case we would use the following;

--[[ First, we need to change 'score.' From my experience, having ".Value" in a variable just doesn't seem to work. That may or may not be the case, but just for safety, I would recommend removing the .Value from the variable.

**Same thing with the ".Text".

]]--

local text1 = --Put the "ClicksNumLabelText line here, without the .Text
local text2 = --Same thing, but with the Shadow one

local score = script.ClicksNum

function onMouseClick(click)
	score.Value = score.Value + 1
	text1.Text = tostring(score.Value)
	text2.Text = tostring(score.Value)
end

-- And here is where you would have the connect

NOTE: The above script has not, in any way, been tested. It is rough code, and with that, you are bound to find bugs.

Change your connect line (14) to:

button.ClickDetector.MouseClick:connect(onMouseClicked)

10 comments

0

ToString is a function (and is case sensitive, so it's "tostring") not a method. Change the "score.Value:ToString()"s to "tostring(score.Value)" and that should work, assuming text1 and text2 are filled in.

0

Ah. I don't normally use ToString, thanks for the fixing. Edited

0

I tried testing the code. It doesn't seem to be working for me. Here's what it looks like after I fixed it: http://prntscr.com/2xcb6g (yes, there is a ClickDetector inside the part)

0

Is there an Output?

0

Aswell, on Line 9, there appears to be a space after ". Value". Try to remove that space.

0

Nope. It says nothing in the output.

0

Ahhh... It was hiding near the top. Here's what it says: http://prntscr.com/2xcse3

0

Read my newest edit

0

It works now! Thank you very very much for helping me resolve this problem!

0

Okay nevermind. For some reason it works in studio solo mode but it doesn't work in online mode. Should I change it to a localscript?

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