How do u throw a sword w/ FastCast module?

  1. What do you want to achieve?
    I wanna switch from using RaycastHitbox module to this FastCast module.
    The result should look something similar to this:
    https://streamable.com/fdpwal

  2. What is the issue?
    The sword doesn’t move. It does the throw animation and stays frozen in mid air.

  3. What solutions have you tried so far?
    I’ve been looking all over the api for anything I might be missing. I don’t understand what’s wrong with my code.

swordClone = nil;
hitSomething = false;

-- new caster for throwable sword
Caster = FastCast.new()

-- not sure what I would do with the origin, lastPoint, rayDir, displacement, or cosmeticBulletObject
Caster.LengthChanged:connect(function(...)
	print(...)
end)

-- Upon the caster hitting something
OnHitConnection = Caster.RayHit:Connect(function(hit,hitPos, normal, material, cosmeticBulletObject)
	print'RayHit Event called'
	if not hit then
		return
	end
	print('Hit obj found',hit:GetFullName())
	if (hit ~= swordClone) and (hit.CanCollide or hit.Parent:FindFirstChild('Humanoid') ) then
		hitSomething = hit
		doDamage(hit,DefaultDamage*3)
		if swordClone then
			swordClone.CFrame = swordClone.CFrame*CFrame.new(0,-3,0)
		end
		
		--OnHitConnection:Disconnect()
		
		wait(1)
		
		if swordClone then
			swordClone.Anchored = false
			swordClone.CanCollide = true
		end
	end
end)

function throwAttack(whereToThrow)
	print'Throw attack!'
	SpearThrowAnim:Play(.1,1,2)
	Handle.SwingSound:Play()
	SpearThrowAnim.Stopped:Wait()
	
	
	swordClone = Handle:Clone()
	swordClone.CFrame = CFrame.new(Handle.Position,whereToThrow)*CFrame.Angles(math.rad(-90),0,0)
	swordClone.Anchored = true
	swordClone.Parent = workspace--Char
	Tool.Parent = game.ServerScriptService -- I don't use ServerStorage because this script is inside the tool, I don't want the script to end here.
	
	local origin = swordClone.Position
	local direction = (origin-whereToThrow).Unit
	local BULLET_GRAVITY = Vector3.new(0,-1,0)
	
	-- Fire/throw the sword!
	Caster:Fire(origin, direction*3, 100, swordClone, Char, false, BULLET_GRAVITY)
	
	hitSomething = false
	
	
	-- make sword pick-up-able stuff (you can ignore the stuff after this line)
	local EInteractObj = game.ServerStorage.EtoInteract:Clone()
	
	EInteractObj.Parent = swordClone
	local toolTaken = false
	EInteractObj.OnPlayerActivate.Event:Connect(function(PlayerWhoClicked)
		if toolTaken then
			return
		end
		toolTaken = true
		local gave = give(PlayerWhoClicked,Tool)
		if gave then
			Player = PlayerWhoClicked
			Char = Player.Character
			Hum = Char:WaitForChild('Humanoid')
			OnHitConnection:Disconnect()
			swordClone:Destroy()
		else
			toolTaken = false
		end
	end)
end

The throwAttack function is called whenever the user activates the throw-move.
whereToThrow is the Mouse.Hit.p value (this is a server script though)

2 Likes

I might end up writing my own thing for this

EDIT: I ended up writing my own thing for this from scratch. I might open source it in the future if I feel like it.