TweenService breaking a OnTouch Event

I wanted the tweened objected to be Destroyed when it touches anything

As you can see in the Gyazo the part still going after hitting the walls.
https://gyazo.com/e18ec6cc7c5c1e84ecb1e4042ab4f304

I didn’t find anything that could help me, hope you can help me.

Tween

Event.OnServerEvent:Connect(function(Player, pos)

	local char = Player.Character
	local Root = char.HumanoidRootPart


	local Fire = RS.FireFist:Clone()
	Fire.Parent = char
	Fire.Position = Root.Position + Root.CFrame.LookVector *6
	Fire.CFrame = CFrame.lookAt(Root.Position, pos)
	
	
	
	local info = TweenInfo.new(20)
	local tween = TS:Create(Fire, info, {Position = Fire.CFrame.LookVector * 1000})
	tween:Play()
	
end)

1 Like

The Touched Event should be able to help you. Maybe try this

Event.OnServerEvent:Connect(function(Player, pos)

	local char = Player.Character
	local Root = char.HumanoidRootPart

	local Fire = RS.FireFist:Clone()
	Fire.Parent = char
	Fire.Position = Root.Position + Root.CFrame.LookVector *6
	Fire.CFrame = CFrame.lookAt(Root.Position, pos)

	local WasFireDestroyed = false

	Fire.Touched:Connect(function(part)
		-- Checks if they are a player or not
		if (part.Parent:FindFirstChild("Humanoid")) then
			-- This makes sure that it doesn't get destroyed
			-- by touching the player that caused the fire in animation
			-- but it will be destroyed by other players
			if (Player.Name ~= part.Parent.Name) then
				WasFireDestroyed = true
				Fire:Destroy()
			end
		else
			WasFireDestroyed = true
			Fire:Destroy()
		end
	end)

	local info = TweenInfo.new(20)
	local tween = TS:Create(Fire, info, {Position = Fire.CFrame.LookVector * 1000})
	tween:Play()

	-- I also recommend keeping this in because if it doesn't touch anything and say,
	-- the player shoots it up into the air then it could be there forever.

	wait(20)

	if (not WasFireDestroyed) then
		Fire:Destroy()
	end
end)

I don’t recommend you use tween service or touched event for that matter.

I would rather use either a Vector force, BodyMover or raycasting and run service or even just use FastCast.

The reason being is that touch is inaccurate and tween service is generally used for when you want to move something from A to B.

Also you can use the Debris service I like this

game:GetService("Debris"):AddItem(Projectile,20)

Instead of

is there a way to control the direction with debris?

Debris is just an easier and more cleaner way of getting rid of objects in the game.

Regarding the module that you should probably use I will link it here. Making a combat game with ranged weapons? FastCast may be the module for you!

It has a bunch of special parameters too like pierce, bullet drop it even supports PartCache

Add denounce on the touch script to prevent the player from touching the part multiple times in a millisecond

The Touched event still triggers when you’re standing on it because of your animation, so like BoredScripts said, add a debounce to it.

1 Like

Already tried that but it is not an infinite yield its is just not getting the touch event

Is the part anchored? Anchored parts do not trigger BasePart.Touched.

This is a common problem in roblox. If you want to achieve the same effect without using Anchor, just use BodyPosition. This will keep the part in place (assuming you set it’s force high enough) and it will also simulate physics. Also you will not need to tween the position, just set the target position in the BodyPosition and the part will move there.

So I should use BodyPosition Instead of TweenService or BodyVelocity?

This is my suggestion yes. You can use BodyVelocity too, it’s just that BodyPosition is more similar to the TweenService because you just set a position.