Getting an error

Alright, so I am getting an error, but in another script, the if statement works.

The error I am getting is “Attempt to index nil with ‘Team’”.

This is my script.

local Diastole = script.Parent.ScreenPart.Screen.Frame.Diastole
local Systole = script.Parent.ScreenPart.Screen.Frame.Systole

local button = script.Parent.ScreenPart.Screen.Frame 

D = 0 
S = 0 

button.Normal.MouseButton1Click:Connect(function(Player)
	if Player.Team.Name == "Medical Staff" then	
		D = math.random(60,80)
		S = math.random(80,120)

		Diastole.Text = D 
		Systole.Text = S	
	end		
end)


button.Elevated.MouseButton1Click:Connect(function(Player)
	if Player.Team.Name == "Medical Staff" then
		D = math.random(15,80)
		S = math.random(120,129)

		Diastole.Text = D
		Systole.Text = S
	end	
end)

button.Hypo.MouseButton1Click:Connect(function(Player)
	if Player.Team.Name == "Medical Staff" then
		D = math.random(50,60)
		S = math.random(50,90)

		Diastole.Text = D
		Systole.Text = S
	end
end)

button.Hyper.MouseButton1Click:Connect(function(Player)
	if Player.Team.Name == "Medical Staff" then
		D = math.random(80,120)
		S = math.random(130,180)

		Diastole.Text = D
		Systole.Text = S
	end
end)

I don’t think MouseButton1Click gives you the player but I could be wrong

Player is referenced by game:GetService("Players").LocalPlayer. So, define that at the beginning of your script to be able to reference the local player in your button connections. MouseButton1Click doesn’t return any parameters as @thebeston123 said.

Like this?

local Diastole = script.Parent.ScreenPart.Screen.Frame.Diastole
local Systole = script.Parent.ScreenPart.Screen.Frame.Systole
local Player = game:GetService("Players").LocalPlayer

local button = script.Parent.ScreenPart.Screen.Frame 

D = 0 
S = 0 

button.Normal.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then	
		D = math.random(60,80)
		S = math.random(80,120)

		Diastole.Text = D 
		Systole.Text = S	
	end		
end)


button.Elevated.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(15,80)
		S = math.random(120,129)

		Diastole.Text = D
		Systole.Text = S
	end	
end)

button.Hypo.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(50,60)
		S = math.random(50,90)

		Diastole.Text = D
		Systole.Text = S
	end
end)

button.Hyper.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(80,120)
		S = math.random(130,180)

		Diastole.Text = D
		Systole.Text = S
	end
end)
2 Likes

@MP3Face It doesn’t work, should it be a local script?

Yes, GUI input can’t be detected from a server script nor can you reference LocalPlayer in one

Add game.Players.PlayerAdded:Connect(function(player) if is a script

Where? needed more words

It is a SurfaceGui, by the way.

If it is a surface gui then it should be a server script, and your script would be like this:

game.Players.PlayerAdded:Connect(function(Player)
local Diastole = script.Parent.ScreenPart.Screen.Frame.Diastole
local Systole = script.Parent.ScreenPart.Screen.Frame.Systole

local button = script.Parent.ScreenPart.Screen.Frame 

D = 0 
S = 0 

button.Normal.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then	
		D = math.random(60,80)
		S = math.random(80,120)

		Diastole.Text = D 
		Systole.Text = S	
	end		
end)


button.Elevated.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(15,80)
		S = math.random(120,129)

		Diastole.Text = D
		Systole.Text = S
	end	
end)

button.Hypo.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(50,60)
		S = math.random(50,90)

		Diastole.Text = D
		Systole.Text = S
	end
end)

button.Hyper.MouseButton1Click:Connect(function()
	if Player.Team.Name == "Medical Staff" then
		D = math.random(80,120)
		S = math.random(130,180)

		Diastole.Text = D
		Systole.Text = S
	end
end)
end
1 Like