Hello, I’m having a problem with my Boss Attacking/Following Script Not working. When the boss is cloned (in a different script and the boss is a character). The script does not work I’ve tried everything and nothing worked.
Match/Lobby Script: local Lobby = 3
local Match = 10
local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status
local MatchCFrame = game.Workspace.Map.PlayerCFrame
local Noob = game.Workspace.Bosses.Noob
local OnTeam = game.ReplicatedStorage.Events.OnTeam
local OnWeapon = game.ReplicatedStorage.Events.OnWeapon
local Bosses = game.Workspace.Bosses:GetChildren()
local HasWeapon = game.ReplicatedStorage.Values.HasWeapon
local CloseGUI = game.ReplicatedStorage.Events.CloseGUI
local SpawnCFrame = game.Workspace.Map.SpawnCFrame
InRound.Changed:Connect(function()
local RandomBoss = Bosses[math.random(1,#Bosses)]
if InRound.Value == true then
for i, v in pairs(game.Players:GetChildren()) do
CloseGUI:FireClient(v)
local char = v.Character
local hum = char:WaitForChild(“Humanoid”)
local HP = char:WaitForChild(“HumanoidRootPart”)
HP.CFrame = MatchCFrame.CFrame
HP.Anchored = true
wait(1)
HP.Anchored = false
local NewBoss = RandomBoss:Clone()
NewBoss.Parent = game.Workspace
NewBoss.Name = RandomBoss.Name…“2”
NewBoss:WaitForChild(“Humanoid”)
RandomBoss.HumanoidRootPart.CFrame = game.Workspace.Map.BossSpawnCFrame.CFrame
–change this to NewBoss when problem fixed
RandomBoss.HumanoidRootPart.Anchored = true
wait(1)
RandomBoss.HumanoidRootPart.Anchored = false
char.InMatch.Value = true
end
else
for i, v in pairs(game.Players:GetChildren()) do
local char = v.Character
char.HumanoidRootPart.CFrame = SpawnCFrame.CFrame
char.HumanoidRootPart.Anchored = true
wait(1)
char.HumanoidRootPart.Anchored = false
char.InMatch.Value = false
for i, v in pairs(game.Workspace:GetChildren()) do
if Bosses[v.Name] and v:IsA("Model") then
print("A Boss Inside WorkSpace")
end
end
end
end
end)
local TheWeapons = {
[“Bat”] = game.ReplicatedStorage.Weapons.Bat,
}
local function RoundTimer()
while wait(0.1) do
for i = Lobby, 0, -1 do
InRound.Value = false
wait(1)
Status.Value = i
print(“Inside Lobby”)
end
for i = Match, 0, -1 do
InRound.Value = true
wait(1)
Status.Value = i
print(“Inside Match”)
end
end
end
spawn(RoundTimer)
DetectPlayer/FollowingPlayer Script: local G = game.Workspace.Bosses.Guest
local OnTeam = game.ReplicatedStorage.Events.OnTeam
local players = game:GetService(“Players”)
local torso = G.UpperTorso
local hp = G.HumanoidRootPart
local NPChum = G.Humanoid
local OnAttackBoss = game.ReplicatedStorage.Events.OnAttackBoss
wait(2)
local function DetectClosestPlayer ()
local Distance = 400
local Target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local hum = v:FindFirstChildOfClass(“Humanoid”)
local btorso = v:FindFirstChild(“LowerTorso”)
if hum and btorso and players and v.InMatch.Value == true and v ~= script.Parent then
if (torso.Position - btorso.Position).magnitude < Distance then
Distance = (torso.Position - btorso.Position).magnitude
Target = btorso
end
end
end
return Target
end
while wait(0.1) do
local bTorso = DetectClosestPlayer()
if bTorso then
NPChum:MoveTo(bTorso.Position)
end
end
To get an answer faster, be sure to format your code using Ctrl+E or the button
First thing I notice is that you are cloning and parenting 1 boss per player, cause you are iterating Players and :Clone() a boss each iteration. Thats intended or should be 1 boss per round?
Then, seems that you are trying to rename the boss as Name…“2”, but the characters were incorrect.
Then, seems you are parenting it to Workspace, and in this line seems that you are looking for the boss in the wrong path: local G = game.Workspace.Bosses.Guest
And many optimizations that could be applied, maybe thats causing the issue.
-- Match/Lobby Script:
local Lobby = 3
local Match = 10
local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status
local MatchCFrame = game.Workspace.Map.PlayerCFrame
local Noob = game.Workspace.Bosses.Noob
local OnTeam = game.ReplicatedStorage.Events.OnTeam
local OnWeapon = game.ReplicatedStorage.Events.OnWeapon
local Bosses = game.Workspace.Bosses:GetChildren()
local HasWeapon = game.ReplicatedStorage.Values.HasWeapon
local CloseGUI = game.ReplicatedStorage.Events.CloseGUI
local SpawnCFrame = game.Workspace.Map.SpawnCFrame
InRound.Changed:Connect(function()
local RandomBoss = Bosses[math.random(1,#Bosses)]
if InRound.Value == true then
for i, v in pairs(game.Players:GetPlayers()) do
CloseGUI:FireClient(v)
local char = v.Character
local hum = char:WaitForChild("Humanoid")
local HP = char:WaitForChild("HumanoidRootPart")
HP.CFrame = MatchCFrame.CFrame
HP.Anchored = true
wait(1)
HP.Anchored = false
-- Boss creation was here, creating 1 boss per player
char.InMatch.Value = true
end
-- 1 boss per round or 1 boss per player ???
local NewBoss = RandomBoss:Clone()
NewBoss.Parent = game.Workspace -- Boss is parented to workspace
NewBoss.Name = RandomBoss.Name.."2"
NewBoss:WaitForChild("Humanoid")
RandomBoss.HumanoidRootPart.CFrame = game.Workspace.Map.BossSpawnCFrame.CFrame
RandomBoss.HumanoidRootPart.Anchored = true
wait(1)
RandomBoss.HumanoidRootPart.Anchored = false
else
for i, v in pairs(game.Players:GetPlayers()) do
local char = v.Character
char.HumanoidRootPart.CFrame = SpawnCFrame.CFrame
char.HumanoidRootPart.Anchored = true
wait(1)
char.HumanoidRootPart.Anchored = false
char.InMatch.Value = false
for i, v in pairs(game.Workspace:GetChildren()) do
if Bosses[v.Name] and v:IsA("Model") then
print("A Boss Inside WorkSpace")
end
end
end
end
end)
local TheWeapons = {
["Bat"] = game.ReplicatedStorage.Weapons.Bat,
}
local function RoundTimer()
while wait(0.1) do
for i = Lobby, 0, -1 do
InRound.Value = false
wait(1)
Status.Value = i
print("Inside Lobby")
end
for i = Match, 0, -1 do
InRound.Value = true
wait(1)
Status.Value = i
print("Inside Match")
end
end
end
spawn(RoundTimer)
-- DetectPlayer/FollowingPlayer Script:
local G = game.Workspace.Bosses.Guest -- Should G be the boss? Cause boss was parented to workspace not Bosses.Guest
local OnTeam = game.ReplicatedStorage.Events.OnTeam
local players = game:GetService("Players")
local torso = G.UpperTorso
local hp = G.HumanoidRootPart
local NPChum = G.Humanoid
local OnAttackBoss = game.ReplicatedStorage.Events.OnAttackBoss
wait(2)
local function DetectClosestPlayer ()
local Distance = 400
local Target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local hum = v:FindFirstChildOfClass("Humanoid")
local btorso = v:FindFirstChild("LowerTorso")
if hum and btorso and players and v.InMatch.Value == true and v ~= script.Parent then
if (torso.Position - btorso.Position).magnitude < Distance then
Distance = (torso.Position - btorso.Position).magnitude
Target = btorso
end
end
end
return Target
end
while wait(0.1) do
local bTorso = DetectClosestPlayer()
if bTorso then
NPChum:MoveTo(bTorso.Position)
end
end
well, every time InRound = true its picking a random boss to clone then.
The for I, v in pairs is looking for all of the current players in the game then teleporting them to the battleground, Then I’m cloning the boss that was picked by local RandomBoss, after that it teleports the boss to the battlegrounds as well the else statement is just teleporting the player back to the lobby and killing the clone.
Yup, thats what I readed in your code, Im saying that you were cloning 1 boss each player in the iteration when checking players, and the parent of the boss is not the one you are using at the bottom of the code for the DetectClosestPlayer() function
When creating the boss: NewBoss.Parent = game.Workspace -- Boss is parented to workspace
When referencing the created boss: local G = game.Workspace.Bosses.Guest -- Should G be the boss? Cause boss was parented to workspace not Bosses.Guest