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

How to change IntValue or NumberValue using script?

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

4 comments

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.

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

0

So I should keep b = a.... and use b.Value instead of b?

0

Yes.

1 answer

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

1 comment

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.

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