I created an attack which basically summons a meteor and uses lerp to bring it down from the sky. The script was originally a local script but had to be changed into a server script so that others could see the attack. I did not have this issue on the local script but now that its a server script I am having issues.
The issue is that while the meteor is falling only the meteor model itself was put into workspace. Only at the last 2 seconds do all of the meteor models children are also put into workspace which makes the meteor appear only at the last second.
Here’s my script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MainFolder = ReplicatedStorage.Events
local Event = MainFolder.Meteor
local meteor = game.ReplicatedStorage.MeteorAttack
local player = game.Players.PlayerAdded:Wait()
local Character = player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local runService = game:GetService('RunService')
local MousePart = ReplicatedStorage.Events:WaitForChild("MousePart")
Event.OnServerEvent:Connect(function(player)
local meteor = game.ReplicatedStorage.MeteorAttack
local summon = ReplicatedStorage.Sounds.Gravity.Meteor.Summon
local explosion = ReplicatedStorage.Sounds.Gravity.Meteor.Explosion
local head = player.Character:FindFirstChild('Head')
local bigmeteor = meteor.Meteor:Clone()
local bomb = bigmeteor.Explosion
local forcefield = bigmeteor.ForcefieldExplosion
local wind = bigmeteor.Circle
local meteoreffect = meteor.Summon:Clone()
local summonpart = meteoreffect
local summonring = meteoreffect.Attachment.ParticleEmitter
local beam = meteor.Beam:Clone()
beam.Transparency = 1
summonring.Enabled = true
meteoreffect.Parent = workspace
beam.Parent = workspace
beam.CFrame = head.CFrame * CFrame.new(0, 1035, 0)
beam.Orientation = Vector3.new(0, 180, -90)
meteoreffect.CFrame = head.CFrame * CFrame.new(0,10,0)
wait(.5)
summon:Play()
player.Character.HumanoidRootPart.Anchored = true
wait(8.5)
local TweenService = game:GetService("TweenService")
beam.Transparency = 0
beam.Size = Vector3.new(2000, 0, 0)
beam.CFrame = head.CFrame * CFrame.new(0, 1035, 0)
beam.Orientation = Vector3.new(0, 180, -90)
local goalbeam = {} --This is the goal for the first tween
goalbeam.Size = beam.Size + Vector3.new(2000, 15, 15)
goalbeam.CFrame = head.CFrame * CFrame.new(0, 1035, 0)
goalbeam.Orientation = Vector3.new(0, 180, -90)
local reverseGoalbeam = {} --This is the goal for the reverse tween
reverseGoalbeam.Size = beam.Size
goalbeam.CFrame = beam.CFrame
goalbeam.Orientation = beam.Orientation
local tweenInfobeam = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
local tweenInfo2beam = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false)
local tweenbeam = TweenService:Create(beam, tweenInfobeam, goalbeam) --This is the first tween
local reverseTweenbeam = TweenService:Create(beam, tweenInfo2beam, reverseGoalbeam)
tweenbeam:Play()
tweenbeam:Play()
summonring.Enabled = false
wait(6.7)
reverseTweenbeam:Play()
bigmeteor.Parent = workspace
bigmeteor:SetPrimaryPartCFrame(head.CFrame * CFrame.new(0,5000,10000))
bomb.Transparency = 1
forcefield.Transparency = 1
wind.Transparency = 1
player.Character.HumanoidRootPart.Anchored = false
runService.Heartbeat:Wait()
local cf = bigmeteor:GetPrimaryPartCFrame()
local hit = head.CFrame
-- Linear Interpolation
for i = 1, 1000 do --1000
bigmeteor:SetPrimaryPartCFrame(cf:Lerp(hit, i/1000))
runService.Heartbeat:Wait()
end
-- Explosion
local smoothness = 25
local explosionradius = 2000
local explosionradius2 = 300
local explosionraidus3 = 350
explosion:Play()
local TweenService = game:GetService("TweenService")
bomb.Transparency = 0
bomb.Size = Vector3.new(explosionradius2, explosionradius2, explosionradius2)
wind.Transparency = 0
wind.Size = Vector3.new(explosionraidus3, explosionraidus3, explosionraidus3)
local goal = {} --This is the goal for the first tween
goal.Size = bomb.Size + Vector3.new(1800, 1800, 1800)
local reverseGoal = {} --This is the goal for the reverse tween
reverseGoal.Size = Vector3.new(50,50,50)
local goal2 = {} --This is the goal for the first tween
goal2.Size = wind.Size + Vector3.new(3500, 250, 3500)
goal2.Transparency = 1
local reverseGoal2 = {} --This is the goal for the reverse tween
reverseGoal2.Size = Vector3.new(50,50,50)
local tweenInfo = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
local tweenInfo2 = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false)
local tweenInfo3 = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
local tweenInfo4 = TweenInfo.new(7, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false)
local tween = TweenService:Create(bomb, tweenInfo, goal) --This is the first tween
local reverseTween = TweenService:Create(bomb, tweenInfo2, reverseGoal)
local windtween = TweenService:Create(wind, tweenInfo3, goal2)
local reversewindtween = TweenService:Create(wind, tweenInfo4, reverseGoal2)
tween:Play()
windtween:Play()
wait(6)
runService.Heartbeat:Wait()
reverseTween:Play()
wait(10)
meteoreffect:Destroy()
bigmeteor:Destroy()
beam:Destroy()
end)