Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Damage counters being weird?

Ok, so, I have a sword system that counts how much damage you do, and put it all into a counter. Most of it works, but when I hit the dummy once, it will tween away twice. Any ideas why?

sword.ShowCounter.OnClientEvent:Connect(function(counter, damage)
	print("fired counter event")
	local tweenService = game:GetService("TweenService")
	local info = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 1, false, 1)
	counter.Parent.NumberToBeShown.Value = counter.Parent.NumberToBeShown.Value + damage
	counter.TextTransparency = 0
	if playingTween then
		playingTween:Cancel()
		resetCounter = false
		print("Changed the resetcounter to false")
	else
		resetCounter = true
		print("changed the resetcounter to true")
	end
	wait(2)
	if playingTween == nil then
		local goal = {TextTransparency = 1}
		local tween = tweenService:Create(counter, info, goal)
		playingTween = tween
		print("there is no tween, so it is making a new tween")
		tween:Play()
		if debugIfs then
			if playingTween == nil then -- debug printing
				print("current tween is nil")
			else
				print("there is a tween playing")
			end
			if resetCounter == nil then
				print("counterreset value is nil")
			else
				print(resetCounter)
			end
		end
		return
	end
	if resetCounter then
		resetCounter = nil
		counter.Parent.NumberToBeShown.Value = 0
		local goal = {TextTransparency = 1}
		local tween = tweenService:Create(counter, info, goal)
		playingTween = tween
		tween:Play()
		print("resetcounter is true resetting the counter")
		if debugIfs then
			if playingTween == nil then -- debug printing
				print("current tween is nil")
			else
				print("there is a tween playing")
			end
			if resetCounter == nil then
				print("counterreset value is nil")
			else
				print(resetCounter)
			end
		end
		return
	else
		print("not resetting the counter, instead just leaving it")
		playingTween = nil
		wait(2)
		local goal = {TextTransparency = 1}
		local tween = tweenService:Create(counter, info, goal)
		playingTween = tween
		tween:Play()
		if debugIfs then
			if playingTween == nil then -- debug printing
				print("current tween is nil")
			else
				print("there is a tween playing")
			end
			if resetCounter == nil then
				print("counterreset value is nil")
			else
				print(resetCounter)
			end
		end
		return
	end
	
end)

1 answer

fixed it, I had the info repeat it once. i just changed the info to 0

local info = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 1)

This discussion is preserved as it was. New answers, comments, and votes are closed.