I'm almost done with a test boss script, and once I get this part fixed, it'll be ready. The problem is that whenever the player is within range of the boss, the boss does its attack function and music plays within a while loop, but when out of range, the music doesn't stop, and the boss keeps attacking. I tried using bool values to break the while loop, I tried using an else in the while loop that enables the attack function. I can't think of anything else.
The script:
function ShootingArc(plrtorso,plr)
while true do
local mouse = plr:GetMouse()
local hrp = plr.Character:WaitForChild("HumanoidRootPart")
local t = 1
local g = Vector3.new(0, -game.Workspace.Gravity, 0);
local x0 = script.Parent.HumanoidRootPart.CFrame * Vector3.new(0, 0,-5)
local v0 = (plrtorso.Position - x0 - 0.5*g*t*t)/t;
local Star = game.Workspace.Fire:Clone()
Star.Name = "SunComet"
Star.Anchored = false
Star.CanCollide = false
Star.Parent = workspace.MagicParts
Star.CFrame = CFrame.new(x0)
Star.Velocity = v0
Star.SunExplosion.Enabled = false
Star.Touched:Connect(function(hit)
if hit.Parent == script.Parent then return end
Star:Destroy()
local Sun = Instance.new("Part")
Sun.Parent = workspace.MagicParts
Sun.Material = "Neon"
Sun.BrickColor = BrickColor.new("Deep orange")
Sun.Position = Star.Position
Sun.Shape = "Ball"
Sun.Size = Vector3.new(0,0,0)
Sun.Transparency = 0
Sun.CanCollide = false
Sun.Anchored = true
local SunPE = game.Workspace.Fire.SunExplosion:Clone()
SunPE.Parent = Sun
SunPE.Enabled = true
for i = 1, 30 do
Sun.Size = Sun.Size + Vector3.new(4,4,4)
Sun.Transparency = Sun.Transparency + 0.05
wait()
end
local h = hit.Parent:FindFirstChild("Humanoid")
local pv = hit.Parent:FindFirstChild("PlayerValue")
if h ~= nil then
if pv ~= nil then
if pv.Value == plr.Name then
print("player found!")
h:TakeDamage(5)
end
end
if h~=nil then
if pv == nil or pv.Value ~= plr.Name then
h:TakeDamage(5)
end
end
end
game.Debris:AddItem(Sun,.05)
end)
game.Debris:AddItem(Star,10)
wait(5)
end
end
dist = 300
game.Players.PlayerAdded:Connect(function(plr)
repeat wait()until plr.Character
local PV = Instance.new("StringValue")
PV.Parent = plr.Character
PV.Name = "PlayerSV"
PV.Value = plr.Name
plr.Character.Humanoid.Died:Connect(function()
if plr.Character:FindFirstChild("PlayerSV") ~= nil then return end
local PB = PV:Clone()
PV.Parent = plr.Character
PV.Name = "PlayerSV"
PV.Value = plr.Name
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
print("touched")
repeat wait() until plr.Character
local char = plr.Character
InRange = true
while InRange == true do
if InRange == false then break end
for i, v in pairs (workspace:GetChildren()) do
if v.ClassName == "Model" then
local h = v:FindFirstChild("Humanoid")
if h ~= nil then
if v:FindFirstChild("PlayerSV") ~= nil then
local torso = v:FindFirstChild("Torso")
local theostorso = script.Parent.Torso
if (script.Parent.Torso.Position - torso.Position).magnitude <= dist then
print((theostorso.Position - torso.Position).magnitude)
if not plr.Character.Torso:FindFirstChild("Sound") then
local Sound = Instance.new("Sound")
Sound.Parent = char.Torso
Sound.SoundId = "rbxassetid://622902771"
Sound.MaxDistance = 300
Sound:Play()
ShootingArc(torso,plr)
end
end
end
end
end
end
wait()
end
print("while loop done")
while (script.Parent.Torso.Position - plr.Character.Torso.Position).magnitude > dist do
print("Out of range!")
InRange = false
wait()
end
end)

2 comments
Did you space out your code so much just to get to 200 lines of code?
No, I don't care about how much code I have. It's just whenever I type after an end I usually tend to press enter and that makes so many unnecessary lines. I deleted most of those lines, just not all of them.