local RunnerSpawn = game.Workspace.RunnerSpawn
local TrapperSpawn = game.Workspace.TrapperSpawn
local Roles = {"Runner","Trapper"}
local MaxRunner = 5
local MaxTrapper = 1
local CurrentRunners = 0
local CurrentTrapper = 0
local Role = ""
function pickRoles()
for i,player in pairs(game.Players:GetChildren()) do --//As i said before, v was player here, so i changed it.
for i,v in pairs(game.Players:GetChildren()) do
for i,v in pairs (Roles, #Roles) do
Role = Roles[math.random(#Roles)]
if Role == "Runner" and CurrentRunners < MaxRunners then
print('Max runners')
Role = "Trapper"
player.Character.Torso.Cframe = TrapperSpawn.CFrame
CurrentTrapper = 1
else
if Role == "Trapper" and CurrentTrapper < MaxTrapper then
print('Max Trappers')
Role = "Runner"
player.Character.Torso.Cframe = RunnerSpawn.CFrame
CurrentRunners = CurrentRunners + 1
end
end
end
end
end
end
wait(10)
pickRoles()
local RunnerSpawn = game.Workspace.RunnerSpawn
local TrapperSpawn = game.Workspace.TrapperSpawn
local Roles = {"Runner","Trapper"}
local MaxRunner = 5
local MaxTrapper = 1
local CurrentRunners = 0
local CurrentTrapper = 0
local Role = ""
function pickRoles()
for i,player in pairs(game.Players:GetChildren()) do --//As i said before, v was player here, so i changed it.
for i,v in pairs(game.Players:GetChildren()) do
for i,v in pairs (Roles, #Roles) do
Role = Roles[math.random(#Roles)]
if Role == "Runner" and {CurrentRunners < MaxRunner} then
print('Max runners')
Role = "Trapper"
player.Character.UpperTorso.CFrame = TrapperSpawn.CFrame
CurrentTrapper = 1
else
if Role == "Trapper" and {CurrentTrapper < MaxTrapper} then
print('Max Trappers')
Role = "Runner"
player.Character.UpperTorso.CFrame = RunnerSpawn.CFrame
CurrentRunners = CurrentRunners + 1
end
end
end
end
end
end
wait(10)
pickRoles()
it teleports players, but it says max trappers even though no one was the trapper
This is a table, by putting it after the and operator, all that happens is that the script checks if it exists at all. it doesnt check the return of the operation inside of it. Use regular brackets.
local RunnerSpawn = game.Workspace.RunnerSpawn
local TrapperSpawn = game.Workspace.TrapperSpawn
local Roles = {"Runner","Trapper"}
local MaxRunner = 5
local MaxTrapper = 1
local CurrentRunners = 0
local CurrentTrapper = 0
local Role = ""
function pickRoles()
for i,player in pairs(game.Players:GetChildren()) do --//As i said before, v was player here, so i changed it.
for i,v in pairs(game.Players:GetChildren()) do
for i,v in pairs (Roles, #Roles) do
Role = Roles[math.random(#Roles)]
if Role == "Runner" and [CurrentRunners < MaxRunner] then
print('Max runners')
Role = "Trapper"
player.Character.UpperTorso.CFrame = TrapperSpawn.CFrame
CurrentTrapper = 1
else
if Role == "Trapper" and [CurrentTrapper < MaxTrapper] then
print('Max Trappers')
Role = "Runner"
player.Character.UpperTorso.CFrame = RunnerSpawn.CFrame
CurrentRunners = CurrentRunners + 1
end
end
end
end
end
end
wait(10)
pickRoles()
The devforum is not a place to go to and get all your errors fixed by someone else. There are exceptions to this, as some errors genuinely cannot be solved by yourself and that is perfectly fine, however I gave you a guide on how roblox errors work yesterday, I hoped it would help you get rid of errors without needing to copy and paste the error onto the devforum.
In this case, youâre doing something like like nil > Number, comparing a number to a nil (undefined, non existent) value. If you arenât sure why something is erroring, doing a google search should be your first go to, how googling Cframe is not a valid member of MeshPart lead to this wiki article. Hopefully this helps with your future coding.
Your variable is incorrectly written compared to the previously declared ones. Try to make sure you type your variables exactly as it says. Hence case sensitivity and spelling.
For instance, you declared MaxRunner but you compared MaxRunners.
For your problem with Max runner print even though there is no runner. Your mistake is rather simple. In the if statement you used this condition
[CurrentRunner < MaxRunner]
The same goes with the trapper one
[CurrentTrapper < MaxTrapper]
And you know that in the line above it. You set the CurrentRunner to 0. In which, make CurrentRunner is lesser than MaxRunner. And so the condition [CurrentRunner < MaxRunner] is true. Thus, running the code below. The simple solution is to change the condition to something like this
[CurrentRunner == MaxRunner]