I am launching missiles out of the missile tanks in the video, and for some reason the missiles go up and down really rapidly on the client side but on the server side everything is fine and there are no problems, is this a studio bug or a script issue?
function AttackClass.Projectile(unit, enemyUnit)
startAttack(unit)
--Units Orientation
local verticalHinge = nil
local horizontalHinge = nil
for _,unitHinge in pairs(unit:GetDescendants())do
if unitHinge:IsA("HingeConstraint") then
if unitHinge.Name == "Vertical" then
verticalHinge = unitHinge
end
if unitHinge.Name == "Horizontal" then
horizontalHinge = unitHinge
end
end
end
game:GetService("RunService").Heartbeat:Connect(function()
local X = (enemyUnit.PrimaryPart.Position.X - horizontalHinge.Attachment1.WorldPosition.X)
local Z = (enemyUnit.PrimaryPart.Position.Z - horizontalHinge.Attachment1.WorldPosition.Z)
local theta = math.atan2(Z,X)
horizontalHinge.TargetAngle = math.deg(theta) + 90 + unit.PrimaryPart.Orientation.Y
verticalHinge.TargetAngle = 25
end)
wait(2)
--Calculate Position Parts
local partsFolder = Instance.new("Folder", unit)
partsFolder.Name = "bezierParts"
local part0 = Instance.new("Part", partsFolder)
part0.Name = "part0"
part0.Size = Vector3.new(.5,.5,.5)
part0.Anchored = true
part0.CanCollide = false
part0.Transparency = 1
part0.Parent = partsFolder
local part1 = Instance.new("Part", partsFolder)
part1.Name = "part1"
part1.Size = Vector3.new(.5,.5,.5)
part1.CanCollide = false
part1.Anchored = true
part1.Transparency = 1
part1.Parent = partsFolder
local part2 = Instance.new("Part", partsFolder)
part2.Name = "part2"
part2.Size = Vector3.new(.5,.5,.5)
part2.CanCollide = false
part2.Anchored = true
part2.Transparency = 1
part2.Parent = partsFolder
local projectiles = {}
for _, turret in pairs(unit:GetChildren())do
if turret.Name == "Turret" then
local projectile = game.ReplicatedStorage.Objects.AmmoObjects.Missile:Clone()
projectile.PrimaryPart = projectile.CollisionBox
projectile.Recolor.Color = unit.Parent.Parent.TeamValues.TeamColor.Value
projectile.PrimaryPart.CanCollide = false
projectile:PivotTo((turret.CFrame * CFrame.new()))
table.insert(projectiles, projectile)
projectile.Parent = unit
for _, part in pairs(projectile:GetChildren())do
if part:FindFirstChild("WeldConstraint") then
part.WeldConstraint.Part1 = turret
end
end
projectile.PrimaryPart.Anchored = false
local turretObjValue = Instance.new("ObjectValue", projectile)
turretObjValue.Name = "turretObject"
turretObjValue.Value = turret
local startPosition = projectile:SetAttribute("startPos", unit.PrimaryPart.Position)
local timeVariable = projectile:SetAttribute("T", 0)
end
end
local function fireProjectile(projectile)
for _, part in pairs(projectile:GetChildren())do
if part:FindFirstChild("WeldConstraint") then
part.WeldConstraint.Part1 = projectile.PrimaryPart
end
end
game:GetService("RunService").Heartbeat:Connect(function()
if projectile.PrimaryPart == nil then
return
end
part0.Position = projectile.turretObject.Value.Position
part1.Position = (enemyUnit.PrimaryPart.Position + projectile.turretObject.Value.Position)/2 + Vector3.new(0,5,0)
part2.Position = enemyUnit.PrimaryPart.Position
local t = projectile:GetAttribute("T")
t += 0.01
projectile:SetAttribute("T", t)
local i = projectile:GetAttribute("i")
local currentCFrame = quadraticBezier(t,part0,part1,part2)
local nextCFrame = CFrame.new(quadraticBezier(t+0.01,part0,part1,part2))
projectile:PivotTo(CFrame.new(currentCFrame))
projectile:PivotTo(CFrame.lookAt(currentCFrame,nextCFrame.Position))
projectile:PivotTo(projectile.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90),0))
if t >= 1 then
projectile:Destroy()
return
end
end)
end
for _, projectile in pairs(projectiles) do
fireProjectile(projectile)
local smoke = projectile.turretObject.Value.Smoke
projectile.PrimaryPart:FindFirstChild("Trail").Enabled = true
smoke.Enabled = true
wait(2)
smoke.Enabled = false
end
horizontalHinge.TargetAngle = 0
verticalHinge.TargetAngle = 0
endAttack(unit)
end