I’ve looked through some posts on here and I’m actually using one of the methods from one now! but for some reason this doesn’t seem to work : (
currently what I do is do a BlockCast from the sword’s current position to the player’s predicted position, but it doesn’t seem to hit the player if they’re moving or not!
if any of you could please review my code and see what’s wrong I’d be grateful ^^
function events.summon(targets: { [any]: BasePart }, amount: number?, clearance: number?)
amount = amount or 1
clearance = clearance or .5
if targets and type(targets) == "table" then
a_summon:Play(0)
for i, plr in targets do
local swords = {}
local info = TweenInfo.new(.5,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {map,plr}
params.RespectCanCollide = true
local connection = runservice.Heartbeat:Connect(function()
for i, sword: BasePart in swords do
local cf = CFrame.lookAt(sword.Position,plr.Position)*CFrame.fromEulerAngles(0,math.rad(-180),0)
tweenservice:Create(sword,info,{CFrame = cf}):Play()
end
end)
for i = 1, amount do
task.spawn(function()
local sword = darkheart:Clone()
local pos = CFrame.new(root.CFrame.Position)*CFrame.new(math.random(-3,3),math.random(5,6),3)
local cf = CFrame.lookAt(pos.Position,plr.Position)*CFrame.fromEulerAngles(0,math.rad(-180),0)
sword.CFrame = cf
sword.Parent = chr
s_summonspawn.PlaybackSpeed = math.random(98,108)/100
s_summonspawn:Play()
tweenservice:Create(sword,info,{Transparency = 0}):Play()
table.insert(swords, sword)
end)
task.wait(.5)
end
task.wait(clearance)
for i, sword: BasePart in table.clone(swords) do
task.wait(.25)
table.remove(swords,table.find(swords,sword))
local pred = plr.Position + plr.AssemblyLinearVelocity * .2
sword.CFrame = CFrame.lookAt(sword.Position,pred)*CFrame.fromEulerAngles(0,math.rad(-180),0)
local direction = sword.CFrame:VectorToWorldSpace(Vector3.new(0,0,1))
local ray = workspace:Blockcast(
sword.CFrame,
Vector3.new(2.5,2.5,2.5),
direction*80,
params
)
if ray and ray.Position then
local distance = (sword.Position - ray.Position).Magnitude
local visual_Cast = Instance.new("Part")
visual_Cast.Anchored = true
visual_Cast.CanCollide = false
visual_Cast.Size = Vector3.new(2.5, 2.5, distance)
visual_Cast.CFrame = CFrame.lookAt(sword.Position, ray.Position)*CFrame.new(0, 0, -distance/2)
visual_Cast.Parent = workspace
visual_Cast.Transparency = 0.75
debris:AddItem(visual_Cast,1.5)
s_summonfly:Play()
local hs = s_summonhit:Clone()
hs.Parent = sword
sword.CFrame = CFrame.lookAt(sword.Position,plr.Position)*CFrame.fromEulerAngles(0,math.rad(-180),0)
local cf = CFrame.new(ray.Position)*sword.CFrame.Rotation
local tw = tweenservice:Create(sword,TweenInfo.new(.12,Enum.EasingStyle.Circular),{CFrame = cf})
tw:Play()
local hit = hdthm.castbox(cf,Vector3.new(3, 3, 3),{chr,map})
if #hit > 0 then
for i, part: BasePart in hit do
if part == plr then
damage(part.Parent:FindFirstChildOfClass("Humanoid"),16)
end
end
end
hs:Destroy()
end
task.spawn(function()
task.wait(1.2)
tweenservice:Create(sword,info,{Transparency = 1}):Play()
debris:AddItem(sword,.3)
end)
end
connection:Disconnect()
end
end
end