Tripwire System Cannot Check IDs

It’s been a LONG time since I’ve tried to script anything, so I am relying on tutorials. But so far, none of them can explain this.
Essentially, I am trying to make a tripwire system where if the player touches a part, but they don’t have the right ID in either their hands nor their inventory, it sets off an alarm bell and changes the color of a console to red. I believe the error is the lines where I am trying to check the player for what IDs they have (to determine if the alarm should be sounded).

The error message is: image|637x25 but because I am rusty (and also very stupid) I can’t for the life of me figure out how to fix it.

local alarm = script.Parent.SFX_Alarm
local light = script.Parent.Parent.Tripwire_Console.T1
local debounce = false

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then --- The issue is in the 3 lines below this
		local Tool = hit.Parent:FindFirstChild("Humanoid"):FindFirstChild("M-ID")  or hit.Parent.Character:FindFirstChild("M-ID")
		local Tool2 = hit.Parent:FindFirstChild("Humanoid"):FindFirstChild("R-ID")  or hit.Parent.Character:FindFirstChild("R-ID")
		local Tool3 = hit.Parent:FindFirstChild("Humanoid"):FindFirstChild("D-ID")  or hit.Parent.Character:FindFirstChild("D-ID")
	
		if Tool or Tool2 or Tool3 then return end --- If any of the local tools are found, do not set off the alarm
	
		if not debounce then
			print("Sounding the Alarm!")
			debounce = true
			alarm:Play()
			light.Material = "Neon"
			task.wait(60)
			debounce = false
		end
	end
end)

or hit.Parent.Character:FindFirstChild("M-ID")

The issue is that hit.Parent is your character, not your player, so it doesn’t have a Character. The way you can solve this is to make a variable called player as the first line in the event:

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local Tool = hit.Parent:FindFirstChild("M-ID")  or player.Backpack:FindFirstChild("M-ID")
-- copy this for the rest of the tools, then write the rest of the code you have
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.