Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this script change a value?

Asked by 10 years ago

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.

0
Try changing the name of the numbervalue. There is 2 "Value" on line 3. ultimate055 150 — 10y

1 answer

Log in to vote
2
Answered by 10 years ago

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

0
Thanks! It worked! I had thought I tried that but appereantly I didn't. Thanks! AwsomeSpongebob 350 — 10y
Ad

Answer this question