I figured it out on my own after a while, thanks for nothing

I am making a stealth game and I'm testing a feature where if an NPC sees you with a gun equipped, you will enter combat mode. Otherwise, if it's not equipped you won't. I wasn't sure how to do that so I made a script where when the gun is equipped, an invisible part from ServerStorage will be moved into workspace. If you touch the part, you go into Combat mode. If you unequip the gun, the barrier goes back to ServerStorage.

The problem? NO errors. It just... doesn't work.

The Script in the Gun:

function addNoGun()
local server = game.ServerStorage:WaitForChild("NoGun")
server.Parent = game.Workspace
end

function removeNoGun()
local work = game.Workspace:WaitForChild("NoGun")
work.Parent = game.ServerStorage
end

script.Parent.Equipped:Connect(addNoGun)
script.Parent.Unequipped:Connect(removeNoGun)

The Combat script:

local part = game.Workspace:WaitForChild("NoGun")
local debounce = false

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		local h = hit.Parent.Humanoid
		debounce = true
		script.Parent.Script2.Disabled = false
		script:Destroy()
	end
end)

script2:

	script.Parent.LocalScript.Disabled = false
	script.Parent.Parent.Trespass:Destroy()
	game.Workspace.Guard:Destroy()
	game.Workspace.Guard2:Destroy()
	game.Workspace.Guard3:Destroy()
	game.Workspace.Guard4:Destroy()
	game.ServerStorage.Guards.Parent = game.Workspace
	script:Destroy()

That's all of the scripts! This is a game breaking bug and it's an essential feature for the game so PLEASE help me!

Any help is appreciated, thank you for reading.

2 comments

0

probably use :Equipped()

0

where?