Ive been trying to work on this for so long, each time it just gives a error or just dosen’t work.
Anybody know any yt videos or articles out their on it?
Ive been trying to work on this for so long, each time it just gives a error or just dosen’t work.
Anybody know any yt videos or articles out their on it?
Send code so we can help!! It’s better for us to help you with YOUR code, rather than to copy off someone else (:
Aight
local RolesModule = require(script.Roles)
local SpawnModule = require(script.WaveBasedRoles)
local assignedRoles = {}
function assignRole(player:Player, role, subclass)
if assignedRoles[role] and assignedRoles[role][subclass] then
if assignedRoles[role][subclass] >= RolesModule.Roles[role][subclass].limit then
return false -- Role limit reached
end
else
assignedRoles[role] = assignedRoles[role] or {}
assignedRoles[role][subclass] = (assignedRoles[role][subclass] or 0) + 1
end
-- Assign the role and item to the player (you may want to add the logic here)
-- Update the RolePicked GUI
local playerGui = player:FindFirstChild("PlayerGui")
if playerGui then
local rolePickedGui = playerGui:FindFirstChild("Starting_Role")
if rolePickedGui then
rolePickedGui.Enabled = true
rolePickedGui.HolderFrame.Role.Text = role
rolePickedGui.HolderFrame.SubClass.Text = subclass
end
end
print(player.Name .. " assigned to " .. role .. " (" .. subclass .. ") with item: " .. RolesModule.Roles[role][subclass].item)
return true
end
function roundstart()
local players = game.Players:GetChildren()
local playerCount = #players
print("Amount of players: " .. playerCount)
local roleNames = {}
for roleName in pairs(RolesModule.Roles) do
table.insert(roleNames, roleName)
end
for _, player in ipairs(players) do
local roleAssigned = false
while not roleAssigned do
local roleIndex = math.random(1, #roleNames)
local role = roleNames[roleIndex]
local subclassNames = {}
for subclassName in pairs(RolesModule.Roles[role]) do
table.insert(subclassNames, subclassName)
end
if #subclassNames > 0 then
local subclassIndex = math.random(1, #subclassNames)
local subclass = subclassNames[subclassIndex]
roleAssigned = assignRole(player, role, subclass)
end
end
end
end
function spawnwave()
local friendlyEntity = SpawnModule.pickEntity(SpawnModule.Friendly)
local hostileEntity = SpawnModule.pickEntity(SpawnModule.Hostile)
print("Spawning friendly: " .. friendlyEntity)
print("Spawning hostile: " .. hostileEntity)
-- Logic to spawn the entities goes here
-- Example: spawn(friendlyEntity) and spawn(hostileEntity)
end
while wait() do
local players = game.Players:GetChildren()
-- Reset assigned roles before starting a new round
assignedRoles = {}
print("Intermission")
print("Starting round")
roundstart()
wait(160)
-- Randomly spawn waves based on roles and subclasses
for role, subclasses in pairs(RolesModule.Roles) do
for subclass, data in pairs(subclasses) do
if assignedRoles[role] and assignedRoles[role][subclass] then
spawnwave(role, subclass)
end
end
end
wait(160)
wait(546)
end
Main handler
Roles module
local RolesModule = {}
RolesModule.Roles = {
ClassD = {
TeamColor = Color3.new(1, 0.580392, 0.235294),
SubClassColor = Color3.new(1, 0.784314, 0.521569),
Default = {item = "Crowbar", limit = 10},
Elite = {item = "Pistol", limit = 2}
},
Janitor = {
TeamColor = Color3.new(1, 0.580392, 0.235294),
SubClassColor = Color3.new(1, 0.784314, 0.521569),
Default = {item = "Broom", limit = 10},
Elite = {item = "Security Key", limit = 1}
},
Researcher = {
TeamColor = Color3.new(1, 0.580392, 0.235294),
SubClassColor = Color3.new(1, 0.784314, 0.521569),
Default = {item = "Clipboard", limit = 10},
Elite = {item = "Lab Keycard", limit = 3}
},
Guard = {
TeamColor = Color3.new(1, 0.580392, 0.235294),
SubClassColor = Color3.new(1, 0.784314, 0.521569),
Default = {item = "Handcuffs", limit = 10},
Elite = {item = "Rifle", limit = 5}
},
SCP = {
TeamColor = Color3.new(1, 0.580392, 0.235294),
SubClassColor = Color3.new(1, 0.784314, 0.521569),
SCP_049 = {item = "Scalpel", limit = 1},
SCP_457 = {item = "Flamethrower", limit = 1},
SCP_096 = {item = "Claws", limit = 1}
}
}
-- some are just for testing
return RolesModule
The reason why your code is probably erroring is cuz of this line
You actually have to get the array of players currently ingame by doing game.Players:GetPlayers()
Anyways here’s some of my nitpicks with the first script. Ignore if you don’t care lol
I heard while wait() do is unreliable and might stop sometimes. Might as well use a while true loop. You could also try RunService.Heartbeat and add a debounce to the entire block of code inside since RunService.Heartbeat does not yield the entire thread
I see some comments where it asks you to add logic. Just wondering if you forgot to do that or if that is intentional?
Also, what errors are you getting? A screenshot of the output would be fine
Intentional I planned to add more things in the future once I have base
My comments just suck lol
///////
No errors just dosent work
//////////
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.