Client task.wait(duration) not working properly every time

I noticed a problem with using wait() or task.wait() function on client script. Sometimes the task.wait() event is triggered sooner than supposed to and it’s not normal is it something to do with client latency I’m trying to make a duration of 0.5 seconds of increasing exp while at the same time waiting 5 seconds before adding up the total of exp on the speed level

But it seems that after the first 5 seconds the whole total gets added up on each 0.5 seconds each

2 Likes

Can you please provide the code you are using, so we can examine it?

Oh sure man no worry I just waked up

    TotalSeconds += 0.5
	
	if OwnEmerald then
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_EMERALD
		print("OWN EMERALD")
		
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_EMERALD)
	elseif OwnDiamond then
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_DIAMOND
		print("OWN DIAMOND")
		
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_DIAMOND)
	elseif OwnGold then
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_GOLD
		print("OWN GOLD")
		
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_GOLD)
	elseif OwnSilver then
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_SILVER
		print("OWN SILVER")
		
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_SILVER)
	elseif OwnBronze then
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_BRONZE
		print("OWN BRONZE")
		
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER * EXP_MULTIPLIER_BRONZE)
	else
		totalExp += (BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER 
		print("OWN NOTHING")
		print("TOTAL EXP IS : " .. totalExp)
		--event:FireServer((BASE_EXP_ADDER + CalculateWheyMultiplier) * EXP_MULTIPLIER)
	end
	
	--wait(0.5)

	if TotalSeconds >= 2.5 then
		event:FireServer(totalExp)
		totalExp = 0
		TotalSeconds = 0
		print("TASK EXECUTED AT 5 SECONDS")

	end

I also don’t understand an issue why does the event is being fired 2 times by the studio and client after I restart the game with data savings and increasing the level on treadmill

A memory leak would explain why a function connected to an event is running multiple times, but I’ll need to see the whole script to be able to confirm

As for why task.wait is being ignored, you might need to add a debounce to correct that problem

For the memory from my understanding and analyzing it has to do with data that was not saved properly and I was right down the hat as for the task.wait() I have no idea I think it has to do with client latency

1 Like

I’d expect latency to cause the wait duration to increase, though?

Not it’s because I put the wait at the wrong logic place in the code

1 Like

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