so I am using a module called FastCast Redux to make a gun system and it works all good but a problem is that it seems to have an Area of effect of sorts, so the bullet will have good physics until it gets some distance away from the player in which case it will freeze in the air and not move nor despawn, I’m wondering if anyone can help me here, more info below:
the thing is, it works alright if it hits a part or player its just if it gets too far away from the player firing the bullet its almost like it stops working, i have some ideas if they work ill update this post
You get the cast object then connect this event, cannot say it will fix your problem without any reference code to look from.
local function cleanUpBullet(activeCast)
local bullet = activeCast.RayInfo.CosmeticBulletObject
--Debris:AddItem(bullet,1)--normal instance.new clone
local trail = bullet:FindFirstChildWhichIsA("Trail")
if trail then
trail.Enabled = false
end
projectileCache:ReturnPart(bullet)
end
castComponent.CastTerminating:Connect(cleanUpBullet)
Hey so i tried your script and this is the error i get, also this is my entire script (minus the local function that activates a remote event), i also dont understand what you mean by castComponent and what that Debris is.
Script:
local Tool = script.Parent
local fireEvent = Tool:WaitForChild("FireEvent")
local FastCast = require(Tool.FastCastRedux)
local partCache = require(Tool.PartCache)
local GunData = script.Parent.GunData
local AmmoAmount = GunData:GetAttribute("AmountOfAmmo")
local GunDamage = GunData:GetAttribute("Damage")
local GunType = GunData:GetAttribute("GunType")
local BulletFolder = game.Workspace.BulletFolder
local Bullet = BulletFolder.Bullet
local caster = FastCast.new()
local castPerams = RaycastParams.new()
local CastBehavior = FastCast.newBehavior()
local bulletCache = partCache.new(Bullet, 100, BulletFolder)
CastBehavior.RaycastParams = castPerams
CastBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
CastBehavior.AutoIgnoreContainer = false
CastBehavior.CosmeticBulletContainer = BulletFolder
CastBehavior.CosmeticBulletProvider = bulletCache
castPerams.FilterType = Enum.RaycastFilterType.Blacklist
castPerams.IgnoreWater = true
--------------------------------------------------------------------
local function onEquiped()
castPerams.FilterDescendantsInstances = {Tool.Parent, BulletFolder}
end
--------------------------------------------------------------------
local function onLengthChange (cast, lastPoint, direction, length, velocity, bullet2)
if bullet2 then
local BulletLength = bullet2.Size.Z/2
local offset = CFrame.new(0, 0, - (length - BulletLength))
bullet2.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
--------------------------------------------------------------------
local function OnRayHit(cast, result, velocity, bullet2)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(GunDamage)
end
delay(2, function()
bulletCache:ReturnPart(bullet2)
end)
end
--------------------------------------------------------------------
local function Fire(player, mousePosition)
local origin = Tool.Handle.FirePoint.WorldPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 1000, CastBehavior)
end
--------------------------------------------------------------------
local function cleanUpBullet(activeCast)
local bullet = activeCast.RayInfo.CosmeticBulletObject
--Debris:AddItem(bullet,1)--normal instance.new clone
local trail = bullet:FindFirstChildWhichIsA("Trail")
if trail then
trail.Enabled = false
end
bulletCache:ReturnPart(bullet)
end
--------------------------------------------------------------------
fireEvent.OnServerEvent:Connect(Fire)
Tool.Equipped:Connect(onEquiped)
caster.LengthChanged:Connect(onLengthChange)
caster.RayHit:Connect(OnRayHit)
caster.CastTerminating:Connect(cleanUpBullet)