Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

I am trying to make a value constantly update but it wont work, How can I do it?

Asked by 1 year ago

Here is my script, Please help me!

--Variables
local plr = game.Players.LocalPlayer
local cash = script.Parent.Cash.Value
local show = script.Parent

--Script
while (1) do
    show.Text = cash
    print(cash)
    wait(0.1)
end

4 answers

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
1 year ago

Actually, this script works fine. May not be the most efficient, but let's be honest, we all did that once. Although the **while wait(1)* and then the wait(0.1) seems a bit odd. while wait(1.1) will do the same. New thought: Did you make sure the script is inside a label or textbox?

Ad
Log in to vote
1
Answered by
caoshen 96
1 year ago

At the time you define cash, you're explicitly setting it to the Cash's value - it won't update if the value updates, it'll stay at the value it got at that time.

Let's assume cash has a value of 5 when you define it, but it increments - that variable still has a value of 5. In order to overcome this, remove .Value from line 3, and on line 8, in your while loop, change it to:

show.Text = cash.Value

I hope that helped!

Log in to vote
0
Answered by 1 year ago

What you are doing will never work so instead do this

local plr = game.Players.LocalPlayer
local cash = script.Parent.Cash.Value
local show = script.Parent

script.Parent.Cash.Changed:connect(function()
show.Text = cash
print(cash)
wait(0.1)
end)
Log in to vote
0
Answered by 1 year ago

Thx so much it worked!

Answer this question