Hey Everyone,
I’m making a repeat for my story game’s boss fight. It’s supposed to attack the player in the same way until the NPC Is dead.
This is my script:
repeat
wait(.5)
game.ReplicatedStorage.Events.SendLava:FireAllClients()
wait(10)
for _, Tim in pairs(game.ServerStorage.TimClones:GetChildren()) do
spawn(function()
local PlayerToGoTo = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
if not PlayerToGoTo.Character or not PlayerToGoTo.Character.HumanoidRootPart then
return
end
Tim.Parent = game.Workspace
Tim.HumanoidRootPart.CFrame = PlayerToGoTo.Character.HumanoidRootPart.CFrame + Vector3.new(0,5,0)
end)
end
wait(10)
game.Workspace.LavaStart.CFrame = CFrame.new(389.635101, 22648.0625, -419.175079)
for _, Tim in pairs(game.Workspace:GetChildren()) do
if Tim:IsA('Model') and Tim:FindFirstChild('Zombie') and Tim.Name == 'Monster' then
Tim:Destroy()
end
end
wait(1)
until game.Workspace.BossBattle.TimHead.Tim.Humanoid.Health == 0
The problem is, is that it only works once; It doesn’t repeat. I do not understand why. There are no errors. Thank you for any help!
local Courountine = coroutine.wrap(function()
while game.Workspace.BossBattle.TimHead.Tim.Humanoid.Health > 0 do
wait(.5)
game.ReplicatedStorage.Events.SendLava:FireAllClients()
wait(10)
for _, Tim in pairs(game.ServerStorage.TimClones:GetChildren()) do
spawn(function()
local PlayerToGoTo = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
if not PlayerToGoTo.Character or not PlayerToGoTo.Character.HumanoidRootPart then
return
end
Tim.Parent = game.Workspace
Tim.HumanoidRootPart.CFrame = PlayerToGoTo.Character.HumanoidRootPart.CFrame + Vector3.new(0,5,0)
end)
end
wait(10)
game.Workspace.LavaStart.CFrame = CFrame.new(389.635101, 22648.0625, -419.175079)
for _, Tim in pairs(game.Workspace:GetChildren()) do
if Tim:IsA('Model') and Tim:FindFirstChild('Zombie') and Tim.Name == 'Monster' then
Tim:Destroy()
end
end
wait(1)
end
end)
Courountine()
repeat wait() until game.Workspace.BossBattle.TimHead.Tim.Humanoid.Health == 0
and It only works once. The thing i did after the repeat wait doesn’t play.
Sometimes scripts are just confusing. I also have a problem where mine doesnt work and there are no errors. Maybe u could just watch a tutorial on how to make a boss fight or just ask @Merely for help. I heard he is really good at scripting. Im not sure if he has his DMs on tho.
while game.Workspace.BossBattle.TimHead.Tim.Humanoid.Health >= 0 do
wait(10)
game.ReplicatedStorage.Events.SendLava:FireAllClients()
wait(10)
for _, Tim in pairs(game.ServerStorage.TimClones:GetChildren()) do
local PlayerToGoTo = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]
Tim.Parent = game.Workspace
Tim.HumanoidRootPart.CFrame = PlayerToGoTo.Character.HumanoidRootPart.CFrame + Vector3.new(0,5,0)
end
wait(10)
game.Workspace.LavaStart.CFrame = CFrame.new(389.635101, 22648.0625, -419.175079)
print('Hi!')
for _, Tim in pairs(game.Workspace:GetChildren()) do
if Tim:IsA('Model') and Tim:FindFirstChild('Zombie') and Tim.Name == 'Monster' then
Tim:Destroy()
end
end
end
and Hi prints endlessly, but nothing else repeats. Please could you help me?