(Before you read out anything, please primarily focus on the topic, because what I’m showing is a script which is completely fit for me and shouldn’t be questioned, thanks.)
Hello community,
Here’s what happened: I tried to break a loop(The script of the loop is called “BossAttacks”), of course I didn’t know how so I just used a simple part(The part is called Trigga) Now whenever I would trigger a proximity prompt, it should break the loop. It didn’t. I tried using RemoveEvents, to see if that would work, but it didn’t too. But after doing it in another game with barely long lines of codes, the loop somehow just stopped. Here are my scripts:
The Loop, that should’ve broken the whole time:
local TweenService = game:GetService("TweenService")
game.ReplicatedStorage.Evoker.OnServerEvent:Connect(function()
while true do
local var = math.random(1,5)
if var == 1 then -- done walls
print("attack 1")
local wall = Instance.new("Part")
wall.Parent = game.Workspace
wall.Position = Vector3.new(1037.625, 108.795, 1842.45)
wall.Rotation = Vector3.new(0,180,0)
wall.Anchored = true
wall.FormFactor = "Custom"
wall.Size = Vector3.new(105.65, 54.65, 9.9)
wall.Material = "Neon"
wall.Transparency = 0.3
wall.CanCollide = false
local wall1 = Instance.new("Part")
wall1.Parent = game.Workspace
wall1.Position = Vector3.new(1159.015, 108.645, 1720.273)
wall1.Rotation = Vector3.new(0,-90,0)
wall1.Anchored = true
wall1.FormFactor = "Custom"
wall1.Size = Vector3.new(105.65, 54.35, 11.3)
wall1.Material = "Neon"
wall1.Transparency = 0.3
wall1.CanCollide = false
local wall2 = Instance.new("Part")
wall2.Parent = game.Workspace
wall2.Position = Vector3.new(920.065, 108.145, 1720.273)
wall2.Rotation = Vector3.new(0,-90,0)
wall2.Anchored = true
wall2.FormFactor = "Custom"
wall2.Size = Vector3.new(105.65, 54.35, 11.3)
wall2.Material = "Neon"
wall2.Transparency = 0.3
wall2.CanCollide = false
local wall3 = Instance.new("Part")
wall3.Parent = game.Workspace
wall3.Position = Vector3.new(1037.625, 108.795, 1605.4)
wall3.Rotation = Vector3.new(0,180,0)
wall3.Anchored = true
wall3.FormFactor = "Custom"
wall3.Size = Vector3.new(105.65, 54.35, 11.3)
wall3.Material = "Neon"
wall3.Transparency = 0.7
wall3.CanCollide = false
--Rotation on wall creation is irrelevant as long as the speed matches to directions
local speed = 10
local speed1 = -10
local isFast = false
local isFast1 = false
local function changeSpeed()
speed = (speed == -10) and -20 or -10
speed1 = (speed == 10) and 20 or 10
isFast = (speed == -20)
isFast1 = (speed == 20)
local goal = wall.CFrame + Vector3.new(0, 0, speed)
local goal1 = wall1.CFrame + Vector3.new(speed,0, 0)
local goal2 = wall2.CFrame + Vector3.new(speed1,0,0)
local goal3 = wall3.CFrame + Vector3.new(0,0, speed1)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(wall, tweenInfo, {CFrame = goal})
local tween1 = TweenService:Create(wall1, tweenInfo, {CFrame = goal1})
local tween2 = TweenService:Create(wall2,tweenInfo, {CFrame = goal2})
local tween3 = TweenService:Create(wall3,tweenInfo,{CFrame = goal3})
tween:Play()
tween1:Play()
tween2:Play()
tween3:Play()
wall.Transparency = isFast and 0.2 or 0.7
wall1.Transparency = isFast1 and 0.2 or 0.7
wall2.Transparency = isFast1 and 0.2 or 0.7
wall3.Transparency = isFast and 0.2 or 0.7
end
local function takeDamage(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = humanoid.Health - 10
end
end
local function despawnWall()
wall:Destroy()
wall1:Destroy()
wall2:Destroy()
wall3:Destroy()
end
wall.Touched:Connect(function(hit)
if isFast then
takeDamage(hit)
end
end)
wall1.Touched:Connect(function(hit)
if isFast then
takeDamage(hit)
end
end)
wall2.Touched:Connect(function(hit)
if isFast then
takeDamage(hit)
end
end)
wall3.Touched:Connect(function(hit)
if isFast then
takeDamage(hit)
end
end)
wait(5)
for i = 1, 20 do
changeSpeed()
wait(1)
end
despawnWall()
wait(1)
elseif var == 2 then -- done bombs
local MIN_DAMAGE = 25
local MAX_DAMAGE = 75
print("attack 2")
game.Workspace.Bomb1.Transparency = 0.5
game.Workspace.Bomb2.Transparency = 0.5
game.Workspace.Bomb3.Transparency = 0.5
game.Workspace.Bomb4.Transparency = 0.5
wait(5)
local explosion1 = Instance.new("Explosion")
explosion1.Position = Vector3.new(946.215, 80.22, 1722.398)
explosion1.Parent = workspace
explosion1.BlastRadius = 20
game.Workspace.Bomb1.Transparency = 1
explosion1.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
end
end)
local explosion2 = Instance.new("Explosion")
explosion2.Position = Vector3.new(1039.315, 82.82, 1618.048)
explosion2.Parent = workspace
explosion2.BlastRadius = 20
game.Workspace.Bomb2.Transparency = 1
explosion2.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
end
end)
local explosion3 = Instance.new("Explosion")
explosion3.Position = Vector3.new(1039.315, 85.02, 1815.948)
explosion3.Parent = workspace
explosion3.BlastRadius = 20
game.Workspace.Bomb3.Transparency = 1
explosion3.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
end
end)
local explosion4 = Instance.new("Explosion")
explosion4.Position = Vector3.new(1130.965, 87.42, 1724.998)
explosion4.Parent = workspace
explosion3.BlastRadius = 20
game.Workspace.Bomb4.Transparency = 1
explosion4.Hit:Connect(function(hit, distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum then
hum:TakeDamage((1) * (MAX_DAMAGE - MIN_DAMAGE) + MIN_DAMAGE)
end
end)
wait(2)
elseif var == 3 then --done balls
print("attack 3")
local player = game.Players:GetPlayers()[1]
local remoteEvent = game.ReplicatedStorage.SecondAttack
wait(3)
if player and player:IsA("Player") then
remoteEvent:FireClient(player)
else
print("Failed to fire SecondAttack: player is not valid.")
end
wait(13)
elseif var == 4 then -- done lasers
print("attack 4")
local laser = math.random(1,5)
if laser == 1 then
game.Workspace.HollowCircle0.Transparency = 0
game.Workspace.HollowCircle1.Transparency = 0
game.Workspace.HollowCircle2.Transparency = 0
game.Workspace.HollowCircle3.Transparency = 0
game.Workspace.Chargeup:Play()
wait(4)
game.Workspace.HollowLaser0.Transparency = 0
game.Workspace.HollowLaser1.Transparency = 0
game.Workspace.HollowLaser2.Transparency = 0
game.Workspace.HollowLaser3.Transparency = 0
game.Workspace.HollowLaser0.Script.Enabled = true
game.Workspace.HollowLaser1.Script.Enabled = true
game.Workspace.HollowLaser2.Script.Enabled = true
game.Workspace.HollowLaser3.Script.Enabled = true
game.Workspace.GroundLaser:Play()
wait(3)
game.Workspace.HollowCircle0.Transparency = 1
game.Workspace.HollowCircle1.Transparency = 1
game.Workspace.HollowCircle2.Transparency = 1
game.Workspace.HollowCircle3.Transparency = 1
game.Workspace.HollowLaser0.Transparency = 1
game.Workspace.HollowLaser1.Transparency = 1
game.Workspace.HollowLaser2.Transparency = 1
game.Workspace.HollowLaser3.Transparency = 1
game.Workspace.HollowLaser0.Script.Enabled = false
game.Workspace.HollowLaser1.Script.Enabled = false
game.Workspace.HollowLaser2.Script.Enabled = false
game.Workspace.HollowLaser3.Script.Enabled = false
elseif laser == 2 then
game.Workspace.HollowCircle.Transparency = 0
game.Workspace.HollowCircle1.Transparency = 0
game.Workspace.HollowCircle2.Transparency = 0
game.Workspace.HollowCircle3.Transparency = 0
game.Workspace.Chargeup:Play()
wait(4)
game.Workspace.HollowLaser.Transparency = 0
game.Workspace.HollowLaser1.Transparency = 0
game.Workspace.HollowLaser2.Transparency = 0
game.Workspace.HollowLaser3.Transparency = 0
game.Workspace.HollowLaser.Script.Enabled = true
game.Workspace.HollowLaser1.Script.Enabled = true
game.Workspace.HollowLaser2.Script.Enabled = true
game.Workspace.HollowLaser3.Script.Enabled = true
game.Workspace.GroundLaser:Play()
wait(3)
game.Workspace.HollowCircle.Transparency = 1
game.Workspace.HollowCircle1.Transparency = 1
game.Workspace.HollowCircle2.Transparency = 1
game.Workspace.HollowCircle3.Transparency = 1
game.Workspace.HollowLaser.Transparency = 1
game.Workspace.HollowLaser1.Transparency = 1
game.Workspace.HollowLaser2.Transparency = 1
game.Workspace.HollowLaser3.Transparency = 1
game.Workspace.HollowLaser.Script.Enabled = false
game.Workspace.HollowLaser1.Script.Enabled = false
game.Workspace.HollowLaser2.Script.Enabled = false
game.Workspace.HollowLaser3.Script.Enabled = false
elseif laser == 3 then
game.Workspace.HollowCircle0.Transparency = 0
game.Workspace.HollowCircle.Transparency = 0
game.Workspace.HollowCircle2.Transparency = 0
game.Workspace.HollowCircle3.Transparency = 0
game.Workspace.Chargeup:Play()
wait(4)
game.Workspace.HollowLaser0.Transparency = 0
game.Workspace.HollowLaser.Transparency = 0
game.Workspace.HollowLaser2.Transparency = 0
game.Workspace.HollowLaser3.Transparency = 0
game.Workspace.HollowLaser0.Script.Enabled = true
game.Workspace.HollowLaser.Script.Enabled = true
game.Workspace.HollowLaser2.Script.Enabled = true
game.Workspace.HollowLaser3.Script.Enabled = true
game.Workspace.GroundLaser:Play()
wait(3)
game.Workspace.HollowCircle0.Transparency = 1
game.Workspace.HollowCircle.Transparency = 1
game.Workspace.HollowCircle2.Transparency = 1
game.Workspace.HollowCircle3.Transparency = 1
game.Workspace.HollowLaser0.Transparency = 1
game.Workspace.HollowLaser.Transparency = 1
game.Workspace.HollowLaser2.Transparency = 1
game.Workspace.HollowLaser3.Transparency = 1
game.Workspace.HollowLaser0.Script.Enabled = false
game.Workspace.HollowLaser.Script.Enabled = false
game.Workspace.HollowLaser2.Script.Enabled = false
game.Workspace.HollowLaser3.Script.Enabled = false
elseif laser == 4 then
game.Workspace.HollowCircle0.Transparency = 0
game.Workspace.HollowCircle1.Transparency = 0
game.Workspace.HollowCircle.Transparency = 0
game.Workspace.HollowCircle3.Transparency = 0
game.Workspace.Chargeup:Play()
wait(4)
game.Workspace.HollowLaser0.Transparency = 0
game.Workspace.HollowLaser1.Transparency = 0
game.Workspace.HollowLaser.Transparency = 0
game.Workspace.HollowLaser3.Transparency = 0
game.Workspace.HollowLaser0.Script.Enabled = true
game.Workspace.HollowLaser1.Script.Enabled = true
game.Workspace.HollowLaser.Script.Enabled = true
game.Workspace.HollowLaser3.Script.Enabled = true
game.Workspace.GroundLaser:Play()
wait(3)
game.Workspace.HollowCircle0.Transparency = 1
game.Workspace.HollowCircle1.Transparency = 1
game.Workspace.HollowCircle.Transparency = 1
game.Workspace.HollowCircle3.Transparency = 1
game.Workspace.HollowLaser0.Transparency = 1
game.Workspace.HollowLaser1.Transparency = 1
game.Workspace.HollowLaser.Transparency = 1
game.Workspace.HollowLaser3.Transparency = 1
game.Workspace.HollowLaser0.Script.Enabled = false
game.Workspace.HollowLaser1.Script.Enabled = false
game.Workspace.HollowLaser.Script.Enabled = false
game.Workspace.HollowLaser3.Script.Enabled = false
elseif laser == 5 then
game.Workspace.HollowCircle0.Transparency = 0
game.Workspace.HollowCircle1.Transparency = 0
game.Workspace.HollowCircle2.Transparency = 0
game.Workspace.HollowCircle.Transparency = 0
game.Workspace.Chargeup:Play()
wait(4)
game.Workspace.HollowLaser0.Transparency = 0
game.Workspace.HollowLaser1.Transparency = 0
game.Workspace.HollowLaser2.Transparency = 0
game.Workspace.HollowLaser.Transparency = 0
game.Workspace.HollowLaser0.Script.Enabled = true
game.Workspace.HollowLaser1.Script.Enabled = true
game.Workspace.HollowLaser2.Script.Enabled = true
game.Workspace.HollowLaser.Script.Enabled = true
game.Workspace.GroundLaser:Play()
wait(3)
game.Workspace.HollowCircle0.Transparency = 1
game.Workspace.HollowCircle1.Transparency = 1
game.Workspace.HollowCircle2.Transparency = 1
game.Workspace.HollowCircle.Transparency = 1
game.Workspace.HollowLaser0.Transparency = 1
game.Workspace.HollowLaser1.Transparency = 1
game.Workspace.HollowLaser2.Transparency = 1
game.Workspace.HollowLaser.Transparency = 1
game.Workspace.HollowLaser0.Script.Enabled = false
game.Workspace.HollowLaser1.Script.Enabled = false
game.Workspace.HollowLaser2.Script.Enabled = false
game.Workspace.HollowLaser.Script.Enabled = false
end
elseif var == 5 then --done cylinder
print("attack 5")
local player = game.Players:GetPlayers()[1]
local remoteEvent = game.ReplicatedStorage.TriggerAttack
wait(3)
if player and player:IsA("Player") then
remoteEvent:FireClient(player)
else
print("Failed to fire SecondAttack: player is not valid.")
end
wait(10)
end
wait(1)
if workspace.Trigga.Transparency == 1 then break end
end
end)
The ProximityPrompt Script:
script.Parent.ProximityPrompt0.Triggered:Connect(function(player)
game.Workspace.RayCannon:Play()
game.ReplicatedStorage.Attack:FireClient(player)
game.Workspace.RayLaser1.Transparency = 0
script.Parent.BillboardGui:Destroy()
script.Parent.ProximityPrompt0:Destroy()
if game.Workspace.RayLaser.Transparency == 1.1 and game.Workspace.RayLaser0.Transparency == 1.1 and game.Workspace.RayLaser2.Transparency == 1.1 and game.Workspace.RayLaser3.Transparency == 1.1 then
wait(3)
game.Workspace.RayLaser1.Transparency = 1
game.Workspace.Trigga.Transparency = 1
game.Workspace.BossAttacks:Destroy()
else
wait(3)
game.Workspace.RayLaser1.Transparency = 1.1
end
end)
Alternative Proximity Prompt:
script.Parent.ProximityPrompt0.Triggered:Connect(function(player)
game.Workspace.RayCannon:Play()
game.ReplicatedStorage.Attack:FireClient(player)
game.Workspace.RayLaser1.Transparency = 0
script.Parent.BillboardGui:Destroy()
script.Parent.ProximityPrompt0:Destroy()
if game.Workspace.RayLaser.Transparency == 1.1 and game.Workspace.RayLaser0.Transparency == 1.1 and game.Workspace.RayLaser2.Transparency == 1.1 and game.Workspace.RayLaser3.Transparency == 1.1 then
wait(3)
game.Workspace.RayLaser1.Transparency = 1
game.ReplicatedStorage.StopAttacks:FireClient(player)
game.Workspace.BossAttacks:Destroy()
else
wait(3)
game.Workspace.RayLaser1.Transparency = 1.1
end
end)
Remote Script:
game.ReplicatedStorage.StopAttacks.OnClientEvent:Connect(function()
game.Workspace.Trigga.Transparency = 1
game.Workspace.BossAttacks:Destroy()
end)
Why am I mentioning the whole script? I want to know if the script have any traces which avoid the whole loop, which is why everything is so large. Any questions will be answered, thanks.