Basically, when I use an ability that throws a sword, the sword goes in the direction from where I was looking when I first activated the ability.
Look → activate → look somewhere else → sword goes where I first looked
I’ve tried making it delayed when it stores the position, but it clearly doesn’t work.
Video vv
Currently, this is the script:
local module = {}
local runService = game:GetService("RunService")
local effectsRemote = game.ReplicatedStorage.Events.ClientEffect
local replicatedStorage = game.ReplicatedStorage
local modulesFolder = game.ServerStorage.Modules
local muchachoHitbox = require(modulesFolder["MuchachoHitbox"])
local replicatedModulesFolder = game.ReplicatedStorage.Modules
local effectHandler = require(replicatedModulesFolder.EffectHandler)
local hitModule = require(modulesFolder["Hit"])
local cooldowns = {}
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
function module.SwordThrow(character)
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local rootPart = humanoid.RootPart
local ability1Animation = humanoid:LoadAnimation(replicatedStorage.Animations.Monster.Abilities["1x1x1x1"].Ability1)
local abilitySfx = replicatedStorage.SFX.Monster.Abilities["1x1x1x1"].Ability1
local swordModel = replicatedStorage.Items.Other["1x1x1x1Sword"]:Clone()
local sfxFolder = replicatedStorage.SFX
if cooldowns[character] or player:GetAttribute("Attacking") or player:GetAttribute("Stunned") then return end
cooldowns[character] = true
params.FilterDescendantsInstances = {character}
local hitbox = muchachoHitbox.CreateHitbox()
hitbox.CFrame = swordModel
hitbox.Size = Vector3.new(4,4,4)
hitbox.Visualizer = true
hitbox.OverlapParams = params
hitbox.Key = character.Name .. "m1Attack"
hitbox.VelocityPrediction = true
player:SetAttribute("Attacking", true)
rootPart.Anchored = true
effectHandler.Effects(character.Torso, abilitySfx, false)
task.delay(2/3, function() -- Delayed to .667 seconds
hitbox:Start()
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Parent = swordModel
swordModel.Parent = workspace
swordModel.CFrame = rootPart.CFrame
bodyVelocity.Velocity = rootPart.CFrame.LookVector * 100
task.delay(15, function() -- Destroy sword after 15 seconds
swordModel:Destroy()
end)
end)
hitbox.Touched:Connect(function(hit)
local possibleCharacter = hit.Parent
local ehum
if player:GetAttribute("Stunned") then
return
else
if (possibleCharacter:IsA("Model") and possibleCharacter:FindFirstChild("Humanoid")) then
ehum = possibleCharacter:FindFirstChild("Humanoid")
elseif (possibleCharacter.Parent:IsA("Model") and possibleCharacter.Parent:FindFirstChild("Humanoid")) then
ehum = possibleCharacter.Parent:FindFirstChild("Humanoid")
elseif (possibleCharacter.Parent.Parent:IsA("Model") and possibleCharacter.Parent.Parent:FindFirstChild("Humanoid")) then
ehum = possibleCharacter.Parent.Parent:FindFirstChild("Humanoid")
elseif (possibleCharacter.Parent.Parent.Parent:IsA("Model") and possibleCharacter.Parent.Parent.Parent:FindFirstChild("Humanoid")) then
ehum = possibleCharacter.Parent.Parent.Parent:FindFirstChild("Humanoid")
else
return
end
end
local hitSound = sfxFolder.Monster.HitSFX["BloodVariant"..tostring(math.random(1,5))]
local hs = hitModule.Hit(ehum, 25, humanoid.RootPart.CFrame.LookVector * 5, 2, 2)
if hs then
effectHandler.Effects(character.Torso, hitSound, true)
end
end)
ability1Animation:Play()
task.wait(1)
player:SetAttribute("Attacking", false)
rootPart.Anchored = false
task.wait(0)
cooldowns[character] = false
end
return module



