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?
increaseDamage.MouseButton1Click:Connect(function()
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
end
end)
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.
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.