A question about GUI buttons

I’m making a project where a player can interact with their stats such as increasing their damage. In the following code you will notice that I add a wait function and that function fixed the issue of not refreshing their stat damage in their first click. Why did the wait function fixed the issue?

			if  plrSkillPoints.Value >= 1  then
				increaseStatsEvent:FireServer(plrDamage, plrSkillPoints, ammountWalkSpeedDamage)
				skillPointsText.Text = "SkillPoints: "..plrSkillPoints.Value -- this text is refreshing just fine only the damageText has the issue and I don't know why
				wait(.1) -- If i remove this the damageText changes on the second click
				damageText.Text = "Damage: "..plrDamage.Value

It takes some time for client-server communication so most of the times you wont be able to update the text the moment you use :FireServer, you could use RemoteFunction instead of RemoteEvent and that will yield the script until server returns that it finished changing your stats.

1 Like

That makes sense. But why the textLabel called ‘skillpointsText’ has no issue? And is it bad practice to use wait function on this case?

Its possible that if you are changing it first on the server it updates fast enough, but depending on ping and other factors you might have issues with it. Using wait is just a temporary solution as sometimes it will take longer for it to update and even wait wont help, so it would be best to make sure server tells client when it updates the stats and then changing the text.
Also instead of changing stats when you use :FireServer you could connect .Changed to those values so they update when server changes them.

1 Like

I see! Thanks for answering my questions

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.