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

How to update a NumberValue?

Asked by 3 years ago

Hello, I recently got stuck into a problem while scripting a BillboardGui for an NPC for my Roblox game, the NumberValue called "energy" inside the NPC doesn't update via scripts or manually via properties. I've tried switching to an IntValue however that didn't work too. This server script checks if "energy" NumberValue is smaller than 50 or 25 and then changes the NPC's WalkSpeed, and also sets a BillboardGui size.

01local energy = script.Parent.Parent.Parent.Parent.energy
02 
03while wait(0.1) do
04    energy.Value = script.Parent.Size.X.Scale * 100
05    script.Parent.Size = UDim2.new(energy.Value/100, 0, 0.03, 0)
06    print("updated to " .. energy.Value/100)
07if energy.Value > 95 then
08    script.Parent.Size = UDim2.new(0.95, 0, 0.03, 0)
09    energy.Value = 95
10end
11if energy.Value < 50 then
12        script.Parent.Parent.Parent.Parent.Humanoid.WalkSpeed = 14
13end
14 
15if energy.Value < 25 then
16        script.Parent.Parent.Parent.Parent.Humanoid.WalkSpeed = 10
17    end
18end

As you can see in line 6, I made it so it prints the "energy" value, however, this prints every 0.1 seconds "updated to 0.94999998807907".

1 answer

Log in to vote
2
Answered by 3 years ago

Firstly, You're basically printing a number between 0 and 1 since you times by 100 initially and then divide by 100 in the print

Secondly, I do not see any code that would externally change the size of the UI, you're basically just continuously setting the size to the same value over and over again.

Ad

Answer this question