I scripted an “Event” where it spawn an ufo and aliens spawn on the map, the aliens go after players but when the last player is dead or if its one player and that player dies the aliens go at the place where the player died and start jittering, and it lags a lot, is there any way for me to stop them from jittering and creating this much lag?
PS: each alien has it’s own script and it lags bc the AssemblyLinearVelocity value changes a lot of times in a short time
Event script:
while wait(10) do
game.Lighting.ClockTime = 4
local ufo = game.ReplicatedStorage.UFO:Clone()
ufo.Parent = workspace
game.ReplicatedStorage.UFOEvent.Aliens:FireAllClients()
local count = 0
repeat
wait(1)
local alienclone = game.ReplicatedStorage.alien:Clone()
alienclone.Parent = workspace
alienclone.Script.Enabled = true
local xpos = math.random(-1700,1700)
local zpos = math.random(-1700,1700)
alienclone:MoveTo(Vector3.new(xpos,alienclone.PrimaryPart.Position.Y,zpos))
count += 1
until count == 15
wait(300)
game.Lighting.ClockTime = 14
ufo:Destroy()
for i,v in workspace:GetChildren() do
if v.Name == "alien" then
v:Destroy()
end
end
game.ReplicatedStorage.UFOEvent.StopAliens:FireAllClients()
end
Alien script:
wait(0.2)
local npc = script.Parent
local listofplrs = {}
for i,v in game.Players:GetChildren() do
table.insert(listofplrs, v)
end
if listofplrs ~= {} then
local randomNum = math.random(1,#listofplrs)
local char = listofplrs[randomNum].Character
game["Run Service"].Stepped:Connect(function()
if char and listofplrs ~= {} then
npc.PrimaryPart.AssemblyLinearVelocity = ((char.PrimaryPart.Position-npc.PrimaryPart.Position) + Vector3.new(0,18,0)).Unit*40
npc.PrimaryPart.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if plr.leaderstats.Size.Value >= 1000 then
plr.leaderstats.Size.Value -= 1000
game.ReplicatedStorage.UFOEvent.AfterDeath:FireAllClients()
Do()
npc:Destroy()
else
otherPart.Parent:FindFirstChild("Humanoid").Health = 0
game.ReplicatedStorage.UFOEvent.AfterDeath:FireAllClients()
Do()
npc:Destroy()
end
end
end)
end
end)
end