I have a problem with Tweening

Recently, I have been having a problem with Tween Service. So when the player touches the Block, another block is supposed to appear (similar to the Custom Duels queueing system). I used a Touched event like you should, but I also used a TouchEnded event for when the player steps off the block. For some reason, the TouchEnded event plays immediately after the Touched event, which isn’t supposed to happen unless the player steps off the block. I used prints to make sure that I was right. Here is the prints and code below.

s1p1.Touched:connect(function(hit)
	if not debounce1 then
		debounce1 = true
		tween1:Play()
		print("Tween1")
	end
end)

s1p1.TouchEnded:connect(function()
	if not deboucne2 then
		deboucne2 = true
		tween2:Play()
		print("Tween2")
	end
end)

Screen Shot 2020-12-01 at 1.49.32 PM

I hope someone can tell me what went wrong, thanks.

1 Like

Could i see the whole script if there is one!

That’s not really necessary, I just asked for help on why the Touch and TouchEnded didn’t work.

Any limb that touches the part and immediately pulls away (say, a leg that moves due to the walking animation) will trigger both events in quick succession. A decent way of getting around this is to call :GetTouchingParts() on the part when a touch is ended to ensure no part of the character is still touching before running the second tween.

So would I say something like

part:GetTouchingParts()

I’ve never used that function before so I don’t know how to implement it.

You can try using Magnitude or checking a specific body part:

s1p1.Touched:connect(function(hit)
	if not debounce1 and hit.Name == "LeftFoot" then
		debounce1 = true
		tween1:Play()
		print("Tween1")
	end
end)

When a part of the player’s character stops touching the block, do the following:

  1. Get the character from the part that is no longer touching, which is passed through by TouchEnded
  2. Get all parts touching the block using :GetTouchingParts()
  3. Check if any of the parts belong to the character from step 1
  4. If none of the parts belong to the character, THEN play tween2

I’ll see if this works, thank you.

Use a non-CanCollide part that a player can go inside of to detect players entering/leaving the area, instead of a part that’s flat on the ground.
You will also need to deal with TouchEnded firing for each part that stops touching the part!

I have posted about using Touched/TouchEnded in a reliable way elsewhere on the forum, but it might be easier to just :GetTouchingParts() on a loop if you can’t wrap your head around it.