Am I using fastcast wrong?

So I have a gun with a handle and a part welded to it called firepoint, where I want the bullet to fire out of. Inside the tool I have the fastcast module, one client script and one server script, as well as a remote event called fire and one called shoot, shoot deals damage and fire fires a bullet. here is the server side script

local debounce = 0
local FastCast = require(script.Parent.FastCastRedux)
local caster = FastCast.new()
local FirePoint = script.Parent.Part
FastCast.VisualizeCasts = false
local bulletFolder = game.Workspace.BulletFolder
local function fire(player, mousePosition)
	local origin = FirePoint.OriginPosition
	local direction = (mousePosition - origin).Unit
	caster:Fire(origin, direction, 20)
end
local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Size = Vector3.new(1.5,1.5,1.5)
bulletTemplate.Shape = "Ball"
bulletTemplate.BrickColor = BrickColor.new("Yellow flip/flop")

local castPerams = RaycastParams.new()
castPerams.IgnoreWater = true
castPerams.FilterType = Enum.RaycastFilterType.Blacklist

local castBehavior = FastCast.newBehavior()
castBehavior.Acceleration = 10
castBehavior.RaycastParams = castPerams
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate

local function onLengthChanged(cast,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



local function Shoot(player,Target)
	if debounce == 0 then
		debounce = 1
		if Target ~= nil then
			local human = Target.Parent:findFirstChild("Humanoid")
			if human then
			if Target.Name == "Head" then
				human:TakeDamage(30)
			elseif Target.Name == "HumanoidRootPart" then
				human:TakeDamage(30)

				else
					human:TakeDamage(30)
			end
			end
		end
		script.Parent.Handle.Fire:Play()
		debounce = 0
	end
end
script.Parent.Equipped:Connect(function()
	castPerams.FilterDescendantsInstances = {script.Parent.Parent, bulletFolder}
end)
script.Parent.Fire.OnServerEvent:Connect(fire)
script.Parent.Shoot.OnServerEvent:Connect(Shoot)
caster.LengthChanged:Connect(onLengthChanged)

and then I want to call it when the tool is activated, this is the client sided script

local var = 10
local shouldFollowMouse = false
local animid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Animate").toolnone.ToolNoneAnim.AnimationId
local doNotInterrupt = false
local Players = game:GetService("Players")
local anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.ReloadAnim)


local function thingy()
local character = game.Players.LocalPlayer.Character
if character.Parent == "Backpack" then return end
	local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
	

local function click()
		if var > 0 then
			script.Parent.Fire:FireServer(mouse.Hit.Position)
			var = var - 1
			script.Parent.Shoot:FireServer(mouse.Target)
			local gun = script.Parent.Handle
			else
			if doNotInterrupt == false then
				doNotInterrupt = true
				script.Parent.Handle.Reload:Play()
				anim:Play()
				wait(1)
				var = 10
				doNotInterrupt = false
			end
		end
end
script.Parent.Activated:Connect(click)

end

script.Parent.Equipped:Connect(thingy)

now it does damage and all, but dosn’t shoot a bullet?
please help.

--do this
caster.RayHit:Connect(Shoot)
--instead of this
script.Parent.Shoot.OnServerEvent:Connect(Shoot)

I would recommend you to get the fast cast redux example and read its codes, it explains pretty much everything. Your shoot function is wrong, let me edit it for a second.

2 Likes
function Shoot(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
	local result = raycastResult.Instance
	local normal = raycastResult.Normal
	local point = raycastResult.Position
	if not result then return end

	--deal damage
end
caster.RayHit:Connect(Shoot)

this should do it. Basically, your deal damage script was not connected the the rayhit event of the fast cast. So nothing happens when you hit

1 Like

the shoot function has nothing to do with fastcast the shoot function just deals damage the fire function is what shoots the bullet

I’m quite confused with what you are trying to achieve. So you want the fast cast to deal damage or you want the mousehit deal damage. Because if you want the mousehit to deal damage that’d make no sense for you to use fast cast ._.

the mouse hit deals damage the bullet is for effect but you helped anyway thanks