I'm working on a round system, and I need the script to wait until the character has loaded until it continues but I don't know how. Anyone got a fix?
Here's the script:
local lobbylocation = workspace.Lobby.Lobby.Position + Vector3.new(0, 3, 0)
local gamelocation = workspace.Maps.Main.Position + Vector3.new(0, 3, 0)
local replicatedstorage = game:GetService("ReplicatedStorage")
local timeevent = replicatedstorage:WaitForChild("TimeEvent")
local propcount = replicatedstorage.PropCount
local timeAmount = 20
game.Players.PlayerAdded:Connect(function(plr)
plr.Team = game.Teams.Lobby
replicatedstorage.ServerCount.Value += 1
end)
game.Players.PlayerRemoving:Connect(function()
replicatedstorage.ServerCount.Value -= 1
end)
wait(1)
local function playgame()--300
local timerText = "Time Left: "
while timeAmount > 0 do
timeevent:FireAllClients(timeAmount, timerText)
wait(1)
timeAmount -= 1
end
end
local function playintermission()
local intermission = 10--60
local timerText = "Intermission: "
while intermission > 0 do
timeevent:FireAllClients(intermission, timerText)
wait(1)
intermission -= 1
end
end
local function resetplayers()
for _, plr in pairs (game.Players:GetChildren()) do
plr.Character.HumanoidRootPart.CFrame = CFrame.new(lobbylocation)
end
end
local function teleportplayers()
for _, plr in pairs (game.Players:GetChildren()) do
local huntercount = replicatedstorage:WaitForChild("HunterCount")
if huntercount.Value <= 0 then
huntercount.Value += 1
plr.Character.PlayerTeam.Value = "Hunters"
plr.Character.HumanoidRootPart.CFrame = CFrame.new(gamelocation)
plr.Team = game.Teams.Hunters
else
propcount.Value += 1
plr.Character.PlayerTeam.Value = "Props"
plr.Character.HumanoidRootPart.CFrame = CFrame.new(gamelocation)
plr.Team = game.Teams.Props
end
end
end
local function resetall()
for _, plr in pairs(game.Players:GetChildren()) do
local huntercount = replicatedstorage:WaitForChild("HunterCount")
huntercount.Value = 0
propcount.Value = 0
plr.Character.Humanoid.Health = 0
plr.Team = game.Teams.Lobby
if plr.Team == game.Teams.Hunters then
local propgun = plr:FindFirstChild("PropGun") or plr.Character:FindFirstChild("PropGun")
if propgun then
propgun:Destroy()
end
end
end
end
local function hunterwait()
for _, plr in pairs (game.Players:GetChildren()) do
if plr.Team == game.Teams.Hunters then
local hunterscreen = plr.PlayerGui:WaitForChild("HunterScreen")
hunterscreen.Enabled = true
wait(5)
hunterscreen.Enabled = false
local propgun = replicatedstorage:WaitForChild("PropGun")
local gunclone = propgun:Clone()
gunclone.Parent = plr.Backpack
end
end
end
while wait() do
if replicatedstorage.ServerCount.Value >= 1 then
resetplayers()
playintermission()
teleportplayers()
hunterwait()
if propcount.Value == 0 then
print("HUNTERS WIN")
resetall()
end
playgame()
if propcount.Value == 0 then
print("HUNTERS WIN")
resetall()
else if timeAmount == 0 then
print("PROPS WIN")
resetall()
end
end
end
end

6 comments
which line does it say?
You can probably avoid this and use Player.RespawnLocation and Player:LoadCharacter() so you don't have to mess around with positions but for this you would need spawnlocations in your map
Hi tabbo, thanks for your comment where exactly did you insert the line of code that i sent?
Right at the top, before all the functions etc. - I've fixed it just by adding a simple wait(2) (Probably not the most ideal way but it works)
Hi there I have edited my code, sorry i just forgot 1 line, i hope it works now, its way more efficient than wait()!!
@TabooAntonioiscool