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

Why wont this script change a value?

This script is suppose to add 1 to a NumberValue when clicked IF the value is less than 11, but there are no errors or anything for that matter in the output and it doesn't work. Whats wrong?

-- Made by AwsomeSpongebob

HairVal = game.Workspace.Dummy.Hair.Value.Value
Button = script.Parent

Button.MouseButton1Click:connect(function()
	if HairVal < 11 then
		HairVal = HairVal + 1
	end
end)

P.S. Dummy and Hair are both models, there is a numbervalue located inside the Hair model.

1 comment

0

Try changing the name of the numbervalue. There is 2 "Value" on line 3.

1 answer

✓ Accepted answer

Where you have put

HairVal = game.Workspace.Dummy.Hair.Value.Value

You are setting HairVal to the value itself, so maybe 4 or 8, not the actual object. In this case you want to do this:

HairVal = game.Workspace.Dummy.Hair.Value
04
Button = script.Parent
05
 
06
Button.MouseButton1Click:connect(function()
07
    if HairVal.Value < 11 then
08
        HairVal.Value = HairVal.Value + 1
09
    end
10
end)


This way you are not accessing a literal value, like 7 or 4, but the actual objects value.

-- If I helped leave a +1 Rep <3

1 comment

0

Thanks! It worked! I had thought I tried that but appereantly I didn't. Thanks!

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