I am making a boss attack where the boss throws the sword, but the tween doesnt work
local rig = script.Parent
local electricarea = script.Parent.Parent["Electric Area"]
local area = {}
area.CFrame = CFrame.new(-3328.699, 131.421, -4901.823) -- center of arena
area.Size = Vector3.new(1239.84, 226.444, 608.11) -- size of arena
area.OverlapParams = OverlapParams.new()
area.OverlapParams.FilterType = Enum.RaycastFilterType.Whitelist
local walkanim = rig.Humanoid.Run
local loadwalk = rig.Humanoid:LoadAnimation(walkanim)
local swinganim = rig.Humanoid.SwingSword
local loadswing = rig.Humanoid:LoadAnimation(swinganim)
local throwanim = rig.Humanoid.SwordThrough
local loadthrow = rig.Humanoid:LoadAnimation(throwanim)
function getCharactersInArena()
local whitelist = {}
for _,player in pairs(game.Players:GetChildren()) do
if player.Character ~= nil and player.Character:FindFirstChild("HumanoidRootPart") ~= nil then
table.insert(whitelist,player.Character.HumanoidRootPart)
end
end
area.OverlapParams.FilterDescendantsInstances = whitelist
local arr = workspace:GetPartBoundsInBox(area.CFrame,area.Size,area.OverlapParams)
return arr
end
local function findNearestPlayer(boss)
local characters = {}
local charactersInArena = getCharactersInArena()
for _,root in pairs(charactersInArena) do
local player = game.Players:GetPlayerFromCharacter(root.Parent)
local arr = {}
arr.Player = player
arr.Character = player.Character
arr.Position = player.Character.HumanoidRootPart.Position
arr.Magnitude = (boss.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude
table.insert(characters,arr)
end
table.sort(characters,function(a,b) return a.Magnitude < b.Magnitude end)
return characters[1]
end
local canwalk = true
rig.Humanoid.MoveToFinished:Connect(function()
if canwalk == true then
--canwalk = false
loadwalk:Stop()
loadswing:Play()
script.Parent["electric twin vfx"]:WaitForChild("HitBoxDamage").Kill.Disabled = false
wait(1)
script.Parent["electric twin vfx"].HitBoxDamage.Kill.Disabled = true
loadwalk:Play()
--canwalk = true
end
end)
local TweenService = game:GetService("TweenService")
local shouldthrow = 10
local iflightning = 30
loadwalk:Play()
while wait(1) do
local root = rig.HumanoidRootPart
local nearestPlayer = findNearestPlayer(rig)
if nearestPlayer ~= nil then
if canwalk == true then
rig.Humanoid:MoveTo(nearestPlayer.Position)
print(nearestPlayer.Position)
shouldthrow = shouldthrow - 1
if nearestPlayer.Magnitude > 30 and canwalk == true then
local sword = game.ServerStorage.BossAttacks.TwinBossAttacks:WaitForChild("electrictwinsword"):Clone() -- i clone the sword
if shouldthrow <= 0 then
canwalk = false
loadwalk:Stop()
loadthrow:Play()
sword.Parent = workspace
sword:SetPrimaryPartCFrame(CFrame.new(script.Parent["electric twinvfx"].PrimaryPart.Position)) --i put it into the workspace where the other sword was
local tweeninfo = TweenInfo.new(2)
local goal = {
Position = Vector3.new(nearestPlayer.Position.X, 30.322, nearestPlayer.Position.Z)
}
local tween1 = TweenService:Create(sword.PrimaryPart, tweeninfo, goal)
for i,v in pairs(script.Parent["electric twin vfx"]:GetChildren()) do -- i make the original sword invisible
v.Transparency = 1
end
tween1:Play() -- this tween doesnt play, even though it should
wait(5)
for i,v in pairs(script.Parent["electric twin vfx"]:GetChildren()) do
v.Transparency = 0
end
script.Parent["electric twin vfx"].HitBoxDamage.Transparency = 1
canwalk = true
shouldthrow = 10
end
else
shouldthrow = 10
continue
end
else
rig.Humanoid:MoveTo(rig.Parent.Start.Position)
end
end
end
there are no errors, if you want to look at the full script you can, but the parts that arent working are where there are comments
also, how would i make the sword face the player as its being thrown at the player