I am trying to make my loop break whenever the random chosen "killer" either dies or leaves game. I have been trying to figure it out for the last 4 hours and i'm in desperate need for help. Here is the script:
``local go = true
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) while true do while wait(10) do if go == true then go = false local players = game.Players:GetPlayers() local killer = players[math.random(1,#players)] print(killer) game.ReplicatedStorage.KillerName.Value = killer
--edit killer characteristics--
local hat = game.ServerStorage.SpartanHelmet
killer.Character.Humanoid:RemoveAccessories()
killer.Character:WaitForChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=11356448"
killer.Character:WaitForChild("Pants").PantsTemplate = "http://www.roblox.com/asset/?id=11357134"
local hatclone = hat:Clone()
killer.Character.Humanoid:AddAccessory(hatclone)
--add speed,health and jumpheight--
killer.Character.Humanoid.WalkSpeed = 24
killer.Character.Humanoid.MaxHealth = 200
killer.Character.Humanoid.Health = 200
killer.Character.Humanoid.JumpHeight = 10
--show players name--
local swordsmansign = game.ServerStorage.SwordsmanSign:Clone()
swordsmansign.Parent = killer.Character:FindFirstChild("Head")
--show killers picture--
local Players = game:GetService("Players")
local board = game.Workspace.Board.board.SurfaceGui.ImageLabel
local userId = killer.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
board.Image = content
board.Size = UDim2.new(0, 420, 0, 420)
--show killers name--
local label = game.Workspace.LabelPart.SurfaceGui.TextLabel
label.Text = killer.Name
--mapchange--
local function selectmap()
local maps = game.ReplicatedStorage.Maps:GetChildren()
local selected = maps[math.random(1,#maps)]
return selected
end
local randomizedmap = selectmap()
print(randomizedmap)
local randomizedmapclone = randomizedmap:Clone()
randomizedmapclone.Parent = game.Workspace.Map
print("Map installed")
--I am trying to detect, if killer is still here then if their health is down to 0, then break. but if killer left game then break.
end
end
end
end)
end)

1 comment
Im trying to do it at the end of the script, where i commented