Hi! So I'm working on a Hunger-Games style fighting game (Meaning when 1 person is left the game ends) When it gets to the teleporting players to the map part, it does 2 things..
Spawns the first two players, and then when a player dies it spawns the third. There is nothing in my code that should make it do that.
When a player dies, they keep randomly respawning over top of the map as opposed to going in the loser arena. They should automatically teleport to the loser arena upon death. More stuff about my code...
-The on death script that teleports players to the loser part is directly under player, and it is moved there. I do not know if it is deleted at the end or not as the script never gets that far.
-My main script is in Workspace.
-There is currently only one map (hence why there is no map randomizer)
-The on death thing works if i just stick it in the StarterGui, however i only want it active during the rounds and not when players are in the lobby.
-I cut out all the teleporting back and stuff at the end, it isn't important to the question.
Here's the portion of the main script that is important:
local roundtimer = 120
local intermissiontimer = 5
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
local serverstorage = game:GetService("ServerStorage")
local replicatedstorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local gear = serverstorage:WaitForChild("Gear")
local firstrun = true
local playerdata = {}
if firstrun == true then
wait(60)
firstrun = false
end
while true do
--Waits 1 minute in between games
local players = game.Players:GetChildren()
wait(intermissiontimer)
wait(1)
contestants = {}
while true do
print("Finding Players")
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(contestants, player)
end
end
end
if #contestants >= 1 then
break
end
wait(1)
end
--load map
serverstorage:WaitForChild("ForestMap").Parent = game.Workspace
for _, player in pairs (contestants)do
if player and player.Character then
local torso = player.Character:FindFirstChild("Torso")
local humanoid = player.Character:FindFirstChild("Humanoid")
if torso and humanoid then
humanoid.Health = 100
end
local matchtag = Instance.new("StringValue")
matchtag.Name = "MatchTag"
matchtag.Parent = player.Character
print("Added MatchTag")
player.TeamColor = BrickColor.new("Navy blue")
local deathscript = serverstorage:WaitForChild("DeathScript"):clone()
deathscript.Parent = player
torso.CFrame = CFrame.new(game.Workspace:WaitForChild("ForestMap").Baseplate.Position + Vector3.new(math.random(1, 25), 15, math.random(1, 25)))
print("Teleported player")
local backpack = player:FindFirstChild("Backpack")
if backpack then
local allgear = gear:GetChildren()
local randomgear = allgear[math.random(1, #allgear)]:clone()
randomgear.Parent = backpack
end
end
local localtimer = roundtimer
while true do
print("Run")
wait(1)
activecontestants = {}
for _, player in pairs(contestants) do
if player then
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
local matchtag = character:FindFirstChild("MatchTag")
if matchtag and humanoid and humanoid.Health > 0 then
table.insert(activecontestants, player)
end
end
end
end
if #activecontestants < 1 then
print("Less than 1")
break
elseif #activecontestants == 1 then
print("Exactly uno")
break
elseif #activecontestants > 1 then
print("morethanone")
end
end
end
Heres the on death teleport script
script.Parent.Character.Humanoid.Died:connect(function()
script.Parent.TeamColor = BrickColor.new("Maroon")
script.Parent.Character.Humanoid.Torso:Destroy()
end)
Thanks so much for the help!

1 comment
This is a bad "Question". The site is to specifically post pieces of code to get help, I doubt you'll receive a reply on this.