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

How to change IntValue or NumberValue using script?

Asked by 5 years ago

I am using script to change the value by time and use it in other script. But It doesn't result as I expected. Here an example:

cube1

health =  game.Players.LocalPlayer.Character.Humanoid.Health -----> 100
a = script.Parent
b = a.NumberValue.Value
while true do
    b = health
    print (b) -----> 0
end

cube2

health = game.Workspace.cube1.NumberValue.Value
print (health) ---> 0

oof

0
What you're doing is indirectly changing the value, which is why the variable's value changes but the actual value does not. Assign the variable to the value instance, then do b.Value instead of b. DeceptiveCaster 3761 — 5y
0
Yeah, that's because when you're storing a property in a variable, you're not storing the property itself, you're storing the value that this property is set to. So what you're doing is wrong, you are pretty much setting a value(the value that the "Value" property was set to), to a value starmaq 1290 — 5y
0
So I should keep b = a.... and use b.Value instead of b? Organic_Cow -4 — 5y
0
Yes. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago

Try changing cube 1 to:

local health =  game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid", true).Health -----> 100
local a = script.Parent.NumberValue
while wait() do
    a.Value = health
    print(a) -----> 100
end
0
No. Printing "a" prints the name of a, not its value. That's because "a" is a userdata, not a number. a.Value is the number. DeceptiveCaster 3761 — 5y
Ad

Answer this question