AlarmScript Ui not working

I was working on an alarm system that occurs when a part with a text button is clicked. I have got pretty far but I am stuck on the part where I want the ui to change it’s size every second until the reinforcements come. My code does not work, and I think it has something to do with accessing the startergui from workspace. There are no errors. Here are some pictures:

Screen Shot 2020-06-23 at 4.32.11 PM
What is wrong?

Because you are using StarterGui, instead if PlayerGui

2 Likes

so how would I be able to put it in player gui?
players service?
(Sorry I’m not good with ui)

Basically when you put something inside of StarterGui it’s actually replicated to all the players’ PlayerGuis, so the path to them would have to be plr.PlayerGui

so,

warn("ALARM STARTED")
plr.PlayerGui.AlarmUi.Outline.Time.Size = UDim2.new(0, 50, 0, 37)
---rest of the code is the same except I replace game.Startergui with plr---

Inside of the () next to the function put plr.

You need to get the player from the click detector use it to then get the Player GUI

do something like this

local AlarmOn   -- used as debounce

function UIAlarmChanges(player)
	local PlayerGUI = player:FindFirstChild('PlayerGui')  -- fine that players ui that clicked the object
	if not PlayerGUI then return end -- no ui so just exit function 
	PlayerGUI.AlarmUI.OutLine.Time.Size = UDim2.new(0,50,0,37)
	wait(1)	
	---- add the rest in here
end



script.Parent.AlarmPiece.StartAlert.ClickDetector.MouseClick:Connect(function(player)
	if AlarmOn then return end  -- the alarm is already on so exit function
	AlarmOn = true
	UIAlarmChanges(player)
	AlarmOn = false
end)

It works, Thank You! :slight_smile:

1 Like