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

value does not changing. when i print the values ??are equal to 1. How can i fix it?

local b = workspace.Value.Value
local a = workspace.Value2.Value
function onClick(click)
	if a == 1 then
		a = a+ 1
	end
	if b == 2 then
		b = b+1
	end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

1 answer

✓ Accepted answer

Its a simple fix. In your code, you are giving the values off b and a as int / number values rather than an instance, this is because you are saying b is = to the value that is in the first value before its changed so let's say the value off Value is 1, then b is equal to 1 rather than the value, when b is changed, the value won't be. Add prints to test this out, under a = a+ 1, if you add print(a), workspace.Value2.Value you will notice that its different, such as if a = 1 and the value is = 1 at the start, after the code a might be = 2 but the value will stay = 1, so it will print 2 1.

To fix the problem, it is simple. In the code, remove .Value from both off the local values, so the first two lines should be like this.

local b = workspace.Value
local a = workspace.Value2

Now we will have a error, I believe it will be something such as "Attempt to do arithmetic on instance line 5". This is because now we have a instance and a number value.

This is also simple to fix. After the variables you should add the code but with .Value added, so it will become this:

function onClick(click)
    if a == 1 then
        a = a+ 1
    end
    if b == 2 then
        b = b+1
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

So your final code should be

local b = workspace.Value.Value
local a = workspace.Value2.Value
function onClick(click)
    if a == 1 then
        a = a+ 1
    end
    if b == 2 then
        b = b+1
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

1 comment

0

thanks

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