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?
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)
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)
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.
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.)