.Touched event only updating every so often with Fastcasting

Hey, I’ve got this gun which is using the fastcast script to make it more realistic. However, I want the bullet (or snowball in this case) to disappear when it touches something.

The problem is, the .Touched event doesn’t work when it touches another part at first. I thought this was maybe just the way fastcasting worked (like it was defying normal physics or something), but it does eventually all at the one time as so:

Does anyone know what I can do instead of the .Touched event or a way to make it work, or why it’s happening?

Thanks in advance.

Just put the .touched event inside the snowball, for it to delete itself. while ignoring the players character parts and whatever the player is holding.
That’s all there is to it.

That’s what I done, but with fast casting it seems to not actually register what it touches (unless something touches it after it hits something, like a player walk on it)

hmm. try using the .Touched event inside your script that’s doing the fastcasting. I’m no expert at fastcasting, but it’s worth a shot.

When it is hit, Destroy it or something. Like this in the snowball:

script.Parent.Touched:Connect(function(Hit)
        if Hit.Parent then script.Parent:Destroy()
    end
end)

If you’re using FastCast then you should be using CastTerminating instead of Touched. There’s an example gun that the creator of FastCast made that shows you how to use it properly.

This is the relevant code pulled from the example gun:

If you aren’t using PartCache, then you can just shorten it down to something like this:

Caster.CastTerminating:Connect(function(cast)
	local cosmeticBullet = cast.RayInfo.CosmeticBulletObject;
	
	if cosmeticBullet then
		cosmeticBullet:Destroy();
	end 
end)

already suggested this, for them doesnt work since they already did it. sorry

Hey! Thanks so much for this, it seems to work perfectly, one more question though, how would I go around getting what object it hit before it was terminated?

caster.CastTerminating:Connect(function(cast)
	local cosmeticBullet = cast.RayInfo.CosmeticBulletObject;

	if cosmeticBullet then
		
		cosmeticBullet:Destroy();
	end
end)

This is what i’ve got at the moment now (since I wasn’t using PartCache). Would it be something to do with RayInfo?

I’m saying this as I’m trying to kill any player it touches too.

You’d use RayHit for this bit, separate from CastTerminating.

Caster.RayHit:Connect(function(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
	local hitPart = raycastResult.Instance;
	-- do thing to hit object
end)

And I may add here for @Stealthy606 to pay attention to the documentation for RayHit because it covers some important stuff (e.g. don’t delete your bullet in RayHit, that’s a bad idea, and it says why.)

1 Like

Thanks so much! Everything seems to be working now.

Just taken a look at it and will keep it in mind for the future too! Thanks so much.