Why I cant make my script to be only used for certain time?

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

you cant really do that. have you work with a module script before?

Never tried working with a module script before, so doesnt have any experience with that.

you can maybe make functions and call them when a round starts?

look up what a module script is. its a script that does not run until you call a function in it like round start or make teams.

Alright.


1 Like

There not another way to do this without a module script? Im still trying use the module but still having same output error that I had before.

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.

@OmqFroko Does that answer your question about why it is erroring? To check the player’s team you would do plr.Team not plr.Humanoid.Team

Even with the plr.team doesnt work neither.

Workspace.GeneradorS1.Tablet.Screen.SurfaceGui.Frame.Button.Script:26: attempt to index nil with 'Team'

A part of the script

button.MouseButton1Click:Connect(function(plr)
	for i,b in pairs(Enemy) do
		if plr.Team == b then

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. )

Just realized either way you can’t do plr.Team = [Text]
your table would have to define the team like this:

local teams = game:GetService("Teams")

local Enemy = {
	[1] = teams["ST| Subjeto de Teste"],
	[2] = teams["BDK Insurgency"]
}

Let me try again then.


It would look like this:

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

yep, still says that the team is a nil. Maybe the script doesnt work because the script isnt local?

image

Is the actual table word for word to the name of the team?
Have it print the plr and b

Yes, they are names of the team.

Have it: print(plr) and print(b) what does it say?

image

Hmm, okay one sec lemme test this.