Attempting to make a "Hack a metal detector" script

Hello there users of devforum. I am making this script where an enemy team cannot go through a metal detector and if done so it will alarm the metal detector. Though I got this part done. I am making a way for the enemy team to hack it and be able to go through it. It has been semi-completed but whenever the hack is fixed it does the following.

As you can tell it starts to play both the alarm and the sort of pass through signal and debounce wont work as well. Ideas?

Please can you send the code. We can’t really help you without knowing how your system works.

2 Likes

My bad, I forgot.

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
	end
	importantbrick:GetPropertyChangedSignal("BrickColor"):Connect(function()
		if ishacked == false and not hackeddebounce then
			ishacked = true
			hackeddebounce = 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
				task.wait(1)
				debounce = false
				hackeddebounce = false
				ishacked = false
			end)
		end	
	end)
end)

Try have the :GetPropertyChangedSignal part out of the touched event one.

1 Like

Updated code

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

importantbrick:GetPropertyChangedSignal("BrickColor"):Connect(function(player)
	if ishacked == false and not hackeddebounce then
		ishacked = true
		hackeddebounce = 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
			
			task.wait(1)
			debounce = false
			hackeddebounce = false
			ishacked = false		
		end)
	end
end)

Idk what I did wrong but its giving me the error.

Issue seems to be that you have not referenced the alarm (unless I missed it).

1 Like

I just fixed it by adding this

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

But its still giving me the same results from the video

You haven’t checked if ‘player’ exists.

if player then

1 Like

Sorry for not getting back to this but it doesn’t work now.

importantbrick:GetPropertyChangedSignal("BrickColor"):Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		if ishacked == false and not hackeddebounce then
			ishacked = true
			hackeddebounce = true
			TouchPart.Touched:Connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				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

				task.wait(1)
				debounce = false
				hackeddebounce = false
				ishacked = false		
			end)
		end
	end	
end)

As in if your in enemy team it doesn’t even scan you, nor is it printing an error.