I'm very new to scripting so I'm wondering how to add a respawn function to my KOTH game each round. The function would only last during a round and after the round ended they would spawn back at the lobby spawn. Also, my script was working yesterday but now instead of teleporting me to my map is says in output "SpawnCount not a valid member of script". This occurs on line 17 so if you have any help you could offer that would be great. Both scripts for my leaderstats and my gamescript:
`--this is the script for the points
game.Players.PlayerAdded:connect(function(plr) local leaderstats = Instance.new("IntValue", plr) leaderstats.Name = "leaderstats"
local Currency = Instance.new("IntValue", leaderstats)
Currency.Name = "Points"
end)`
`--this is the gamescript
local GameTime = 10
while true do wait(5) local Hint = Instance.new("Hint", workspace) Hint.Text = "Game starting!" wait(1) local RandomNumber = math.random(1, 1) local Map = game.ServerStorage["Map" .. RandomNumber]
Map:Clone().Parent = workspace.MapFolder
ftime = GameTime
local SpawnCount = Map.SpawnCount
for _, v in pairs(game.Players:GetChildren()) do
Player = Instance.new("StringValue", workspace.Players)
Player.Name = v.Name
randomN = math.random(1, SpawnCount.Value)
v.Character.HumanoidRootPart.CFrame = CFrame.new(Map["Spawn" .. randomN].Position+Vector3.new(0, 3, 0))
game.ServerStorage.ClassicSword:Clone().Parent = v.Backpack
end
while true do
wait(1)
ftime = ftime -1
Hint.Text = "Game ending in: " .. ftime
Playing = workspace.Players:GetChildren()
if #Playing == 0 then
for _, v in pairs(workspace.MapFolder:GetChildren()) do
v:Destroy()
end
break
end
if ftime == 0 then
for _, v in pairs(workspace.MapFolder:GetChildren()) do
v:Destroy()
end
break
end
for _, v in pairs(game.Players:GetChildren()) do
if v.Character.Humanoid.Health == 0 then
workspace.Players[v.Name]:Destroy()
end
end
end
for _, v in pairs(workspace.Players:GetChildren()) do workspace[v.Name].Humanoid.Health = 0 game.Players[v.Name].leaderstats.Points.Value = game.Players[v.Name].leaderstats.Points.Value +5 end
end`

2 comments
The code is glitching so btw the writing above each of the lines is coed aswell
Could you loop each player with a script inside player scripts with Boolean value that would set them to another team or “Lobby” team that would then kill/respawn or teleport them?