local Bar = script.Parent local Value = script.Parent.Parent.Enrg.Value while true do wait(0.01) Bar.Size = UDim2.new(Value/100,0,1,0) end
When you start the game it changes the size to the desired size but when energy is changed it does not change with it. Can someone tell me why it doesnt change when value changes?
local Bar = script.Parent local Value = script.Parent.Parent.Enrg -- Removed the .Value while true do wait(0.01) Bar.Size = UDim2.new(Value.Value/100,0,1,0) -- Added .Value to the Udim2 so the value would -- be re counted every 0.01 second! end
The problem is, you are using .Value in variables, this not update the value in variable, for fix you need to get value in loop, not in variable.
Examples:
--<<<< Remember to change the value with server >>>>-- -- Updating local MyValue = workspace.MValue.Value -- If change the value will not update, you need to update the value. while true do MyValue = workspace.MValue.Value -- Update variable to set new value print(MyValue) wait() end -- Updated local MyValue = workspace.MValue -- here get the object of your value while true do -- Because the object is saved in the variable, you can get the updated value at any time. But you need to add MyValue.Value: print(MyValue.Value) -- Print the updated value wait() end
Its simple, only remove .Value from variable and put it on get the value:
local Bar = script.Parent local Value = script.Parent.Parent.Enrg -- Removed the .Value from here. for get the updated value while true do -- Changed wait location. Bar.Size = UDim2.new(Value.Value/100,0,1,0) -- Added .Value after get object to get the updated value wait(0.01) end
Also you can detect if value changed with Instance.Changed
Example:
local obj = workspace.MyValue obj.Changed:Connect(function() -- On change value start a function print("Changed the Value of " .. tostring(obj.Name) .. "!") end)
For your script is here:
local Bar = script.Parent local Value = script.Parent.Parent.Enrg -- Removed the .Value from here. for get the updated value Value.Changed:Connect(function() -- Detect if value changed Bar.Size = UDim2.new(Value.Value/100,0,1,0) -- Added .Value after get object to get the updated value end