Getpropertychangedsignal not working for me

Hello there users of devforum. I have created this script where an enemy team will go through a metal detector and it’ll make an alarm. So far, everythings been done. But i am adding a feature of a way of hacking it and it’s not working correctly. No matter what if its hacked it’ll keep on alarming.

As shown in this video. When its at its normal color it means not hacked but when its red it means hacked… I used print and other debugs and it seems to work so I don’t understand whats happening…

TouchPart.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil and not debounce and ishacked == false then
		debounce = true
		
		if player.TeamColor == BrickColor.new("Lily white") or player.TeamColor == BrickColor.new("Deep orange") then
			
			Alarm.BrickColor = BrickColor.new("Really red")
			script.Parent.DetectedNonAllie:Play()
			script.Parent.DetectedNonAllie.Looped = false
			task.wait(5)
			Alarm.BrickColor = BrickColor.new("Neon orange")
			
			
		elseif player.TeamColor ~= BrickColor.new("Lily white") or player.TeamColor == BrickColor.new("Deep orange") then
			
			Alarm.BrickColor = BrickColor.new("Lime green")
			script.Parent.DetectedAllie:Play()
			script.Parent.DetectedAllie.Looped = false
			task.wait(5)
			Alarm.BrickColor = BrickColor.new("Neon orange")
			
			importantbrick:GetPropertyChangedSignal("BrickColor"):Connect(function()
				if ishacked == false then
					ishacked = true
					TouchPart.Touched:Connect(function()
						if player.TeamColor == BrickColor.new("Lily white") then
							
							Alarm.BrickColor = BrickColor.new("Lime green")
							script.Parent.DetectedAllie:Play()
							script.Parent.DetectedAllie.Looped = false
							task.wait(5)
							Alarm.BrickColor = BrickColor.new("Neon orange")
							
						end
					end)
				end	
			end)
		end
		wait(1)
		debounce = false
	end
end)

This is because you are checking if ishacked is false, and only running the code if its false. So when its true nothing changes, try this:

I also reformatted a bit of it just to look more readable

TouchPart.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil and not debounce then
		debounce = true

		if player.TeamColor == BrickColor.new("Lily white") or player.TeamColor == BrickColor.new("Deep orange") then

			Alarm.BrickColor = BrickColor.new("Really red")
			script.Parent.DetectedNonAllie:Play()
			script.Parent.DetectedNonAllie.Looped = false
			task.wait(5)
			Alarm.BrickColor = BrickColor.new("Neon orange")


		elseif player.TeamColor ~= BrickColor.new("Lily white") or player.TeamColor == BrickColor.new("Deep orange") or ishacked == true then

			Alarm.BrickColor = BrickColor.new("Lime green")
			script.Parent.DetectedAllie:Play()
			script.Parent.DetectedAllie.Looped = false
			task.wait(5)
			Alarm.BrickColor = BrickColor.new("Neon orange")
			
		end
		task.wait(1)
		debounce = false
	end
end)

importantbrick:GetPropertyChangedSignal("BrickColor"):Connect(function()
	if ishacked == false then
		ishacked = true
		TouchPart.Touched:Connect(function()
			if player.TeamColor == BrickColor.new("Lily white") then

				Alarm.BrickColor = BrickColor.new("Lime green")
				script.Parent.DetectedAllie:Play()
				script.Parent.DetectedAllie.Looped = false
				task.wait(5)
				Alarm.BrickColor = BrickColor.new("Neon orange")

			end
		end)
	end	
end)

attempt to index nil with teamcolor

Nevermind I fixed it but now im gonna have to add a debounce for it

1 Like