Comment optimiser un "wait(x)"?

:switzerland:
Bonjour,

Pensez-vous que c’est une bonne chose de faire ce genre de script ? (Le but étant de constamment actualiser une valeur.

Je veux dire, en ajoutant un “wait(x)”, le logiciel est sans cesse en train de calculer.

Est-ce si dérangeant que ca ?? Si oui, comment pourrais-je optimiser ce bout de code ?

:us_outlying_islands:
Hello,

Do you think it’s a good thing to do this kind of script? (The goal is to constantly update a value.

I mean, by adding a “wait(x)”, the software is constantly calculating.

Is it that disturbing?? If so, how could I optimize this piece of code?

local player = game:GetService("Players")
while true do
	script.Parent.Text = player.LocalPlayer.leaderstats.Money.Value
	wait(0.1)
end

Instead I would use this:

player.LocalPlayer.leaderstats.Money:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = player.LocalPlayer.leaderstats.Money.Value
end)

It’s a lot more efficient and only checks once the value changes instead of every 1 tenth of a second.

2 Likes

‘while true do’ has its uses, but this is not one of them. In this instance you’d want to do

local player = game:GetService("Players")
player.LocalPlayer.leaderstats.Money:GetPropertyChangedSignal("Value"):Connect(funciton())
     script.Parent.Text = player.LocalPlayer.leaderstats.Money.Value
end
1 Like

you typed funciton instead of function :skull:

2 Likes

Okay,

Thank you both, @txcIove and @Inpultion !

1 Like