Okay so I’m trying to make my own gun using Fast Cast, but I ran into a problem, where it says: “Attempt to index nil with “Connect”.”
Here’s is the script:
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local fireEvent = tool:WaitForChild("Com")
local FastCast = require(tool:WaitForChild("FastCastRedux"))
local firePoint = handle:WaitForChild("GunFirePoint")
local rs = game:GetService("ReplicatedStorage")
local bulletFolder = rs:WaitForChild("BulletFolder")
local IceBullet = bulletFolder:WaitForChild("IceBullet")
local caster = FastCast.new()
local castParameters = RaycastParams.new()
castParameters.FilterType = Enum.RaycastFilterType.Blacklist
castParameters.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParameters
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletFolder
castBehavior.CosmeticBulletTemplate = IceBullet
function onEquipped()
castParameters.FilterDescendantsInstances = {tool.Parent}
end
function onLengthChanged(caster, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0,0, -(length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
function fire(plr, mousePos)
local origin = firePoint.WorldPosition
local direction = (mousePos - origin).Unit
caster:Fire(origin, direction, 150, castBehavior)
end
fireEvent.OnServerEvent:Connect(fire)
tool.Equipped:Connect(onEquipped)
caster.LengthChanged:Connect(onLengthChanged)
The issue is on the last line, but I don’t see anything that should make it happen.