Screen that shows a frame when a value is reached

I’ve been trying to make a screen showing how many players are in each team and showing a frame when a certain value is reached: eg. If the value is 1 it shows the riot alert. BUT somehow it doesn’t show the alert when that value is reached. Please help.

local SDGetplayers = game.Teams["Security Department"]:GetPlayers()
local SDNumber = #SDGetplayers
local TTFGetplayers = game.Teams["Tactical Task Force"]:GetPlayers()
local TTFNumber = #TTFGetplayers
local TSGetplayers = game.Teams["Test Subjects"]:GetPlayers()
local TSNumber = #TSGetplayers
local RDGetplayers = game.Teams["Research Department"]:GetPlayers()
local RDNumber = #RDGetplayers
local FPGetplayers = game.Teams["Facility Personnel"]:GetPlayers()
local FPNumber = #FPGetplayers
local RaSDGetplayers = game.Teams["Repair and Service Department"]:GetPlayers()
local RaSDNumber = #RaSDGetplayers

while true do
	script.Parent.TeamNumberSD.Text =  SDNumber
	script.Parent.TeamNumberTTF.Text =  TTFNumber
	script.Parent.TeamNumberTS.Text =  TSNumber
	script.Parent.TeamNumberRD.Text =  RDNumber
	script.Parent.TeamNumberFP.Text =  FPNumber
	script.Parent.TeamNumberRaSD.Text = RaSDNumber
	if game.Workspace.Values.EventInProgress.Value == 1 then
		script.Parent.RiotAlert.Visible = true
		script.Parent.BreachAlert.Visible = false
		script.Parent.WarheadAlert.Visible = false
		script.Parent.RaidAlert.Visible = false
	elseif game.Workspace.Values.EventInProgress == 2 then
		script.Parent.RiotAlert.Visible = false
		script.Parent.BreachAlert.Visible = true
		script.Parent.WarheadAlert.Visible = false
		script.Parent.RaidAlert.Visible = false
	elseif game.Workspace.Values.EventInProgress == 3 then
		script.Parent.RiotAlert.Visible = false
		script.Parent.BreachAlert.Visible = false
		script.Parent.WarheadAlert.Visible = true
		script.Parent.RaidAlert.Visible = false
	elseif game.Workspace.Values.EventInProgress == 4 then
		script.Parent.RiotAlert.Visible = false
		script.Parent.BreachAlert.Visible = false
		script.Parent.WarheadAlert.Visible = false
		script.Parent.RaidAlert.Visible = true
	end
	wait()
end
1 Like

Hi,
I noticed the .Value is missing from the elseif statements, but the first one should still update.
I would check if any frames might be Transparent? or overlaying each other? (if they are meant to overlay, check the z-indexes)
Have you tested the other functions which change the EventInProgress values, to make sure they do actually change?
And do the team numbers update properly?

(Also task.wait() is preferred, no real difference, just a pointer)

-- Services
local Teams = game:GetService("Teams")

-- Teams
local TeamsTable = {
	SDGetplayers = Teams["Security Department"],
	TTFGetplayers = Teams["Tactical Task Force"],
	TSGetplayers = Teams["Test Subjects"],
	RDGetplayers = Teams["Research Department"],
	FPGetplayers = Teams["Facility Personnel"],
	RaSDGetplayers = Teams["Repair and Service Department"]
}

-- Values
local EventInProgress = workspace.Values:WaitForChild("EventInProgress")

-- Alerts
local Alerts = {
	[1] = script.Parent.RiotAlert, -- [1] is event number
	[2] = script.Parent.BreachAlert,
	[3] = script.Parent.WarheadAlert,
	[4] = script.Parent.RaidAlert
	-- [5] = etc
}

-- Function
local function UpdateTeams()
	if Alerts[EventInProgress.Value] then
		local SDNumber = #TeamsTable.SDGetplayers:GetPlayers()
		local TTFNumber = #TeamsTable.TTFGetplayers:GetPlayers()
		local TSNumber = #TeamsTable.TSGetplayers:GetPlayers()
		local RDNumber = #TeamsTable.RDGetplayers:GetPlayers()
		local FPNumber = #TeamsTable.FPGetplayers:GetPlayers()
		local RaSDNumber = #TeamsTable.RaSDGetplayers:GetPlayers()

		script.Parent.TeamNumberSD.Text = SDNumber
		script.Parent.TeamNumberTTF.Text = TTFNumber
		script.Parent.TeamNumberTS.Text = TSNumber
		script.Parent.TeamNumberRD.Text = RDNumber
		script.Parent.TeamNumberFP.Text = FPNumber
		script.Parent.TeamNumberRaSD.Text = RaSDNumber

		for _, Alert in Alerts do
			if Alert.Visible then
				Alert.Visible = false
			end
		end

		Alerts[EventInProgress.Value].Visible = true
	end
end

-- Setup
UpdateTeams()

-- Events
for _, Team in TeamsTable do
	Team.Changed:Connect(function()
		UpdateTeams()
	end)
end

EventInProgress.Changed:Connect(function()
	UpdateTeams()
end)
1 Like

Good script but um, I forgot to tell you that when there’s no event the value is 0 and it errors out because of that (the error is: Workspace.StatusScreen.Part.SurfaceGui.Script:48: attempt to index nil with ‘Visible’)
also, I had to fix the UpdateTeams function because it was getting the Teams service instead of the TeamsTable.

1 Like

Fixed! If this doesn’t work then can you show me your Explorer.

1 Like

Doesn’t work even tho the value is changed

Also here is what should happen to the screen if the value is met (what shows up)
image

1 Like

Do u use local or server script?

1 Like

I use Server Scripts for surface guis

How do you change Value manually or through a script and are there any errors?

I used Adonis admin to change it.

Explain in more detail how you do this using Adoins

:s game.Workspace.Values.EventType.Value = (value)

Check whether the value changes exactly with this method.

Create a server script and place it in ServerScriptService and enter this there:

workspace.Values.EventInProgress.Changed:Connect(function(Value)
   print(`Changed! NewValue is {Value}`)
end)

And tell me if it outputs anything when you change Value.

doesn’t output anything, I have 2 other scripts that control the music of each event and an alarm SFX and they output fine (they are in workspace)
image

It looks like Value is changing as a string, try changing the value using a script. Create another server script and put this in there:

local v = workspace.Values.EventInProgress

while task.wait(2) do
	if v.Value > 4 then
		v.Value = 0
	else
		v.Value += 1
	end
end

cycles fine but I had to make an edit since you were getting EventInProgress instead of EventType (I have the same value with the same name)

Okay, now does NewValue output anything?

Yes, it does
image

Great, but SurfaceGui still doesn’t work, right?

It doesn’t show up so it doesn’t work.