Hello, i want to make a game of hide and seek where 2 players are needed to start the round.
then the script picks a random player out of the server to be the hider and teleport them to the desired position. the rest hide for a minute and then after the minute the seeker is released.
the problem is that the script wont put players into the hiders team.
local recol = 0
game.Players.PlayerAdded:Connect(function(plr)
recol = recol + 1
plr.Team = game.Teams.Spectator
print("Added 1")
end)
task.spawn(function()
while task.wait(1) do
if recol >= 2 then
task.wait(20)
local playerCharacters = {}
for _, character in pairs(workspace:GetChildren()) do
if game.Players:FindFirstChild(character.Name) then
table.insert(playerCharacters, character)
end
end
local Seek = playerCharacters[math.random(1, #playerCharacters)]
print(Seek)
local function MakeSeeker()
if recol >= 2 then
game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
end
end
if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
MakeSeeker()
--Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
--Seek.Team = game.Teams.Seeker
else
if Seek.Team == game.Teams.Seeker then
print("this guy is murderer!")
return nil
else
end
task.wait(5)
game.Players:GetPlayerFromCharacter(playerCharacters).Team = game.Teams.Spectator
task.spawn(function()
while wait(0.1) do
local bag = playerCharacters[math.random(1, #playerCharacters)]
if game.Players:GetPlayerFromCharacter(bag).Team == game.Teams.Spectator then
print("Hello printing")
game.Players:GetPlayerFromCharacter(bag).Team = game.Teams.Hiders
end
end
end)
end
end
end
end)
1 Like
If you find a solution, please do share it. thank you!
2 Likes
I fixed up the code for you, and I believe this should work:
local recol = 0
game.Players.PlayerAdded:Connect(function(plr)
recol = recol + 1
plr.Team = game.Teams.Spectator
print("Added 1")
end)
task.spawn(function()
while task.wait(1) do
if recol >= 2 then
task.wait(20)
local playerCharacters = {}
for _, character in pairs(workspace:GetChildren()) do
if game.Players:FindFirstChild(character.Name) then
table.insert(playerCharacters, character)
end
end
local Seek = playerCharacters[math.random(1, #playerCharacters)]
print(Seek)
local function MakeSeeker()
if recol >= 2 then
game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
end
end
if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
MakeSeeker()
--Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
--Seek.Team = game.Teams.Seeker
elseif game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Seeker then
print("this guy is murderer!")
return nil
end
task.wait(5)
for _,v in pairs(playerCharacters) do
if v.Name ~= Seek.Name then
if game.Players:GetPlayerFromCharacter(v).Team == game.Teams.Spectator then
print('aaaa')
game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Hiders
end
end
end
end
end
end)
2 Likes
it still wont put any players into the hider team, no errors tho.
1 Like
it also does not remove the previous seeker when a new seeker has been chosen.
You have to wait 5 seconds because in the code there’s a task.wait(5) in between the code.
i waited 30 seconds in total maybe even longer.
no i mean i want the players to instantly go to a team. like player 2 and player1 instantly go to a team.
and for me the players went both into seekers after like 40 seconds
Did you even update the code? If you want them to instantly go to a team then delete the task.wait(5).
as i said i did update the code and i did wait 40 seconds they both went into seekers.
let me test 1 more time and then ill be for sure.
it works but is there a way to when theres a seeker when the round ends to put all of them back into spectator and repeat the steps?
game.Players.PlayerAdded:Connect(function(plr)
recol = recol + 1
plr.Team = game.Teams.Spectator
print("Added 1")
end)
task.spawn(function()
while task.wait(1) do
if recol >= 2 then
task.wait(20)
local playerCharacters = {}
for _, character in pairs(workspace:GetChildren()) do
if game.Players:FindFirstChild(character.Name) then
table.insert(playerCharacters, character)
end
end
local Seek = playerCharacters[math.random(1, #playerCharacters)]
print(Seek)
local function MakeSeeker()
if recol >= 2 then
game.Players:GetPlayerFromCharacter(Seek).Team = game.Teams.Seeker
end
end
if game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Spectator then
MakeSeeker()
--Seek.HumanoidRootPart.Position = Vector3.new(130.046, 5.5, 0.84)
--Seek.Team = game.Teams.Seeker
elseif game.Players:GetPlayerFromCharacter(Seek).Team == game.Teams.Seeker then
print("this guy is murderer!")
return nil
end
task.wait(5)
for _,v in pairs(playerCharacters) do
if v.Name ~= Seek.Name then
if game.Players:GetPlayerFromCharacter(v).Team == game.Teams.Spectator then
print('aaaa')
game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Hiders
end
end
end
-- do hide and seek code idk
wait(5)
for _,v in pairs(playerCharacters) do
game.Players:GetPlayerFromCharacter(v).Team = game.Teams.Spectator
end
end
end
end)