CBucks = script.Parent.Parent.Button
CBucks.Value = 2
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Why Wont It Give Me 2 CBucks When I Click On The Buttonz?
3 answers
you forgot to type function(onClicked)
both of these scripts should work use this one or the other one
1:
function(onClicked)
CBucks = script.Parent.Parent.Button
CBucks.Value = 2
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
script.Parent.ClickDetector.MouseClick:connect(function()
CBucks = script.Parent.Parent.Button
CBucks.Value = 2
end)
On the
CBucks = script.Parent.Parent.Button
part the "Button" should have a classname of "IntValue" or "NumberValue". if not, then it won't work because a Part doesn't have a Value.
3 comments
Well, on your first method, make sure onClicked is outside the brackets and function must be local. local function onClicked()
"must be local"? do you understand why we make variables local?
It doesn't have to be local unless you're using it in that scope.
Well, I assume that when someone clicks a button, it increases the value by 2. Here's a script and explanation in it, related to my assumptions :
-- Also, I saw that you want it to trigger only once, for this, we will use :Disconnect()
local connection -- Creating a nil variable
local function onClicked()
local CBucks = script.Parent.Parent.Button
-- Make sure CBucks is an IntValue, NumberValue, TextLabel, TextButton and so on..
-- If you want to increase the value by 2, instead setting it to 2
CBucks.Value += 2 -- += is an operator which is for adding to the value [Alt. CBucks.Value = CBucks.Value + 2]
connection:Disconnect() -- Disconnects our function and now cannot be used further until server restarts
end
connection = script.Parent.ClickDetector.MouseClick:Connect(onClicked) -- Capital 'C', assigning our connection variable to our function
Also, please comment if you have any doubts.
Lemme know if it helps!
1 comment
Note that Disconnect is used to disconnect a function, and in your case, the players can still click it after first time, but the values wont change because the function is already disconnected.
Given the info that you have provided me with, I will assume that you are trying to add 2 CBucks(your virtual currency) to a value only once and no more once clicked
so we will set a variable to detect if it has been clicked before or not by adding the following line:
local used = false --automatically false because they didn't use it yet.
so now that we have set the variable what we can do to your script is:
local used = false
function onClicked()
CBucks = script.Parent.Parent.Button --Assuming this is the name of the value since you have a line giving its value property
if used == false then --if they haven't clicked on this before then the code within this if statement will execute.
CBucks.Value = CBucks.Value + 2 --We will add the 2 CBucks just as promised
used = true --Not that they have used it we will set the used variable to true
else --if they already used it and click again
print('Already had used, no more CBucks will be provided') --This will print in the output and nothing else should happen
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
I don't know if this will really work since you didn't really give us enough information but hopefully you can see where this is going and use it to help your problem :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

8 comments
Could you give more info? Or include more of the script. Is it a Local Script or a Server Script?
a script should i do local
are you trying to add 2 to the value everytime they click?
i want it so they can only points by clicking it once but after they can still click it but it just wont give points
What?
Can you explain what CBucks is( IntValue, NumberValue, TextButton etc.)? Also, what you are trying to accomplish by the code and make sure whole code is posted.
If you want to add 2 to the CBucks.Value you have to use (CBucks.Value = CBucks.Value+2). You are currently setting CBucks.Value to 2, not adding.
If you want to add 2 to the CBucks.Value you have to use (CBucks.Value = CBucks.Value+2). You are currently setting CBucks.Value to 2, not adding.