Hello! I am trying to make random Position every second and for some reason the Y Position of the AlienShip decreases after it loops 1 time. I can’t tell why its happening. It’s supposed to stay always 238 but in the screenshot, it always goes down. The Union is has no collision on. Anyone got a solution why?
function AlienAttackEvent()
local Alieninfo = TweenInfo.new(
1,
Enum.EasingStyle.Linear
)
local CloneAlien = ServerStorage.Events.AlienAttack:Clone()
CloneAlien.Parent = Map.Events
local Time = 50
while Time >= 1 do
local RandX = math.random(-317, -51)
local Y = 238
local RandZ = math.random( -84, 158)
local spikepos = Vector3.new(RandX, Y, RandZ)
local AlienTween = TweenService:Create(CloneAlien.AlienShip, Alieninfo, {Position = spikepos})
print(spikepos.Y)
print(CloneAlien.AlienShip.Position.Y)
AlienTween:Play()
Time -= 1
task.wait(1)
if Time == 1 then
CloneAlien:Destroy()
break
end
end
end
you could add a completed event to wait for the previous tween.
here is how
function AlienAttackEvent()
local Alieninfo = TweenInfo.new(
1,
Enum.EasingStyle.Linear
)
local CloneAlien = ServerStorage.Events.AlienAttack:Clone()
CloneAlien.Parent = Map.Events
local Time = 50
while Time >= 1 do
local RandX = math.random(-317, -51)
local Y = 238
local RandZ = math.random( -84, 158)
local spikepos = Vector3.new(RandX, Y, RandZ)
local AlienTween = TweenService:Create(CloneAlien.AlienShip, Alieninfo, {Position = spikepos})
print(spikepos.Y)
print(CloneAlien.AlienShip.Position.Y)
AlienTween:Play()
AlienTween.Completed:Wait() -- Wait for the current tween to finish
Time -= 1
task.wait(1)
if Time == 1 then
CloneAlien:Destroy()
break
end
end
end