I wanted to make it so that this script could be used by 2 teams that would be inside Enemy.
For some reason, I cannot get the script to see the player’s team and thus give this error:
Workspace.GeneradorS1.Tablet.Screen.SurfaceGui.Frame.Button.Script:29: attempt to index nil with 'Humanoid'
local button = script.Parent
local bool = script.Parent.Parent.Parent.Parent.Parent.Parent.Blackout
local Loading = script.Parent.Parent.Loading
local sound = game.Workspace.Powerbreak
local DDE = {
"[DDE] Estagiário",
"[DDE] Técnico Aprendiz",
"[DDE] Técnico Sénior",
"[DDE] Diretor do Comité",
"[DDE/CE] Diretor Executivo",
"[DDE/SR] Serviço de Reator / Level 2",
"[DDE/SR] Serviço de Reator / Level 3",
"[DDE/SR] Serviço de Reator / Level 4",
}
local Enemy = {
"ST| Subjeto de Teste",
"BDK Insurgency"
}
button.MouseButton1Click:Connect(function(plr)
for i,b in pairs(Enemy) do
if plr.Humanoid.Team == b then
if bool.Value == false then
bool.Value = true
Loading.BackgroundColor3 = Color3.new(255, 255, 0)
Loading.Text = "CARREGANDO..."
wait(3)
sound:Play()
Loading.BackgroundColor3 = Color3.new(1, 0.333333, 0)
Loading.Text = "DESATIVO"
button.Text = "RESOLVER"
end
end
end
end)
local lights = {}
for i,v in pairs(workspace.S1Lights:GetDescendants()) do
if v:IsA('PointLight') or v:IsA('SurfaceLight') or v:IsA('SpotLight') then
table.insert(lights,v)
end
end
for i,v in pairs(lights) do
bool.Changed:Connect(function()
v.Enabled = false
v.Parent.Material = Enum.Material.Metal
end)
end
It’s because Humanoid doesn’t have the team value, use plr.Team the humanoid and either way, the humanoid isn’t a part of the plr, it’s a part of the character.
So it is erroring because plr.Humanoid doesn’t exist in the plr, and team isn’t a part of humanoid either way.
That would work, I believe it’s because your trying to loop through a table with no numeric value. The for loop needs it to be in a array for example, if you were to print b, it would be nil because your table doesn’t have any value. You’d have to do:
local Enemy = {
[1] = "ST| Subjeto de Teste",
[2] = "BDK Insurgency"
}
(Edit: because the error is not because plr is nil nor team, it’s because b is nil and your trying to index team with nil. )
local button = script.Parent
local bool = script.Parent.Parent.Parent.Parent.Parent.Parent.Blackout
local Loading = script.Parent.Parent.Loading
local sound = game.Workspace.Powerbreak
local DDE = {
"[DDE] Estagiário",
"[DDE] Técnico Aprendiz",
"[DDE] Técnico Sénior",
"[DDE] Diretor do Comité",
"[DDE/CE] Diretor Executivo",
"[DDE/SR] Serviço de Reator / Level 2",
"[DDE/SR] Serviço de Reator / Level 3",
"[DDE/SR] Serviço de Reator / Level 4",
}
local teams = game:GetService("Teams")
local Enemy = {
[1] = teams["ST| Subjeto de Teste"],
[2] = teams["BDK Insurgency"]
}
button.MouseButton1Click:Connect(function(plr)
for i,b in pairs(Enemy) do
if plr.Team == b then
if bool.Value == false then
bool.Value = true
Loading.BackgroundColor3 = Color3.new(255, 255, 0)
Loading.Text = "CARREGANDO..."
wait(3)
sound:Play()
Loading.BackgroundColor3 = Color3.new(1, 0.333333, 0)
Loading.Text = "DESATIVO"
button.Text = "RESOLVER"
end
end
end
end)
local lights = {}
for i,v in pairs(workspace.S1Lights:GetDescendants()) do
if v:IsA('PointLight') or v:IsA('SurfaceLight') or v:IsA('SpotLight') then
table.insert(lights,v)
end
end
for i,v in pairs(lights) do
bool.Changed:Connect(function()
v.Enabled = false
v.Parent.Material = Enum.Material.Metal
end)
end