Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way I can destroy this team?

Asked by 4 years ago

I've been working on this script for a day and I'm still stuck on destroying the team when nobody is on it.

local teams = game.Teams
local random = 0
local teamColor = teams:GetDescendants()
local playerammount = 0
local blueTeam = game.Teams:GetChildren()
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player) ---- Creates the teams based off player names and color based on random number
    local newTeam = Instance.new("Team",game.Teams)
    newTeam.Parent = teams
    newTeam.Name = (player.Name .. "'s Factory")
    player.Neutral = false
    playerammount = playerammount + 1
    if playerammount == 1 and newTeam.Name == (player.Name .. "'s Factory") then
        newTeam.TeamColor = BrickColor.new("Really blue")
        player.TeamColor = newTeam.TeamColor
    elseif playerammount == 2 and newTeam.Name == (player.Name .. "'s Factory") then
        newTeam.TeamColor = BrickColor.new("Lime green")
        player.TeamColor = newTeam.TeamColor
    elseif playerammount == 3 and newTeam.Name == (player.Name .. "'s Factory") then
        newTeam.TeamColor = BrickColor.new("Deep blue")
        player.TeamColor = newTeam.TeamColor
    elseif playerammount == 4 and newTeam.Name == (player.Name .. "'s Factory") then
        newTeam.TeamColor = BrickColor.new("Crimson")
        player.TeamColor = newTeam.TeamColor
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local Players = game.Players:GetChildren()
    local blueteam = game:GetService("Teams"):getChildren(teamColor.TeamColor == BrickColor.new("Really blue"))
    if player.TeamColor == BrickColor.new("Really blue") then
    blueTeam:Destroy()
    end
end)

Right now its just returning ServerScriptService.Script:33: attempt to call method 'Destroy' (a nil value). Which from my understand is because its trying to destroy the wrong thing. So basically what I want to know is is there a way i can call the Really blue team and then use :Destroy() on it.

1
Nothing in your PlayerRemoving function makes sense. Review it, literally nothing is correct. Nowaha 459 — 4y
0
The blueTeam:Destroy() is not indented NickIsANuke 217 — 4y
0
Yes lua is python indents matter!! or else ur script died User#24403 69 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Figured out what was wrong in most of the versions if i was referencing the color i did team.BrickColor == BrickColor.new when it should have been team.TeamColor == BrickColor.new. Here's what i ended up with

game.Players.PlayerRemoving:Connect(function(player)
    local teama = game.Teams:GetDescendants()
    for _,v in pairs(teama) do
        if v.TeamColor == BrickColor.new("Really blue") and v.Name == (player.Name .. "'s Factory")then
            v:Remove()
            playerammount = 0
        elseif v.TeamColor == BrickColor.new("Lime green") and v.Name == (player.Name .. "'s Factory") then
            v:Remove()
            playerammount = 1
        elseif v.TeamColor == BrickColor.new("Deep blue") and v.Name == (player.Name .. "'s Factory") then
            v:Remove()
            playerammount = 2
        elseif v.TeamColor == BrickColor.new("Crimson") and v.Name == (player.Name .. "'s Factory") then
            v:Remove()
            playerammount = 3
        end
    end
end)

Also thank you Nowaha for making me rethink how to do it.

Ad

Answer this question