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