I have this detection script, and I need it to also detect instances with a Suspicious value inside it. It doesn’t have to go through the detection meter, all it has to do is fire the func with the correct parameter (a message for the notification that the alarm went off)
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
I can always provide more detail if needed.ㅤㅤㅤㅤ
Code:
--detection scripttttttttttttttt
local LookPart = script.Parent.Detector
local func = game.ServerStorage.Bindables.Alarm
local debounce = false
while task.wait() do
for _, Player in pairs(game.Players:GetPlayers()) do
Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Dot = (LookPart.Position - HumanoidRootPart.Position).Unit:Dot(LookPart.CFrame.LookVector)
if Dot > 0.7 then
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params:AddToFilter({LookPart,Character:GetChildren()})
local Raycast = workspace:Raycast(LookPart.Position,-(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude,Params)
if not Raycast then
if game.Players:FindFirstChild(Character.Name) then
local value = game.Players:FindFirstChild(Character.Name).Values.Detectable
if script.Parent.Humanoid.Health ~= 0 then
if value.Value == true then
if debounce == false then
debounce = true
local i = 5
local detectlevel = Player.Values.DetectLevel
detectlevel.Value = i
local ok = true
repeat
if value.Value == true and script.Parent.Humanoid.Health ~= 0 and not workspace:Raycast(LookPart.Position,-(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude,Params) then
ok = true
print(i)
i -= 1
detectlevel.Value = i
task.wait(0.6)
else
print("not ok")
ok = false
debounce = false
detectlevel.Value = 5
break
end
until i == 0 or ok == false
if ok == true then
local reason = " got spotted by a citizen and raised the alarm!"
local plr = game.Players:FindFirstChild(Character.Name)
func:Fire(plr, reason)
debounce = false
end
end
end
end
end
local char = Character
local player = game.Players[char.Name]
end
end
end
end
Well, whatever makes it detect other things. Right now the code only detects characters, then proceeds if they are detectable.
local Raycast = workspace:Raycast(LookPart.Position,-(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude,Params)
if not Raycast then
Hey, a few changes and it should work as you intended. I’ve modified it to check for ‘suspicious’ as ‘detectable.’ It may not be what works best for your scenario because it was a little bit vague imo, but this is the modified code:
local LookPart = script.Parent.Detector
local func = game.ServerStorage.Bindables.Alarm
local debounce = {}
while task.wait() do
for _, Player in pairs(game.Players:GetPlayers()) do
Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Dot = (LookPart.Position - HumanoidRootPart.Position).Unit:Dot(LookPart.CFrame.LookVector)
if Dot > 0.7 then
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params:AddToFilter({LookPart, Character:GetChildren()})
local Raycast = workspace:Raycast(LookPart.Position, -(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude, Params)
if not Raycast then
if game.Players:FindFirstChild(Character.Name) then
local detectableValue = game.Players:FindFirstChild(Character.Name).Values.Detectable
local suspiciousValue = game.Players:FindFirstChild(Character.Name).Values.Suspicious
if script.Parent.Humanoid.Health ~= 0 then
if detectableValue.Value == true or suspiciousValue.Value == true then
if not debounce[Character] then
debounce[Character] = true
local i = 5
local detectLevel = Player.Values.DetectLevel
detectLevel.Value = i
local ok = true
repeat
if (detectableValue.Value == true or suspiciousValue.Value == true) and script.Parent.Humanoid.Health ~= 0 and not workspace:Raycast(LookPart.Position, -(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude, Params) then
ok = true
print(i)
i -= 1
detectLevel.Value = i
task.wait(0.6)
else
print("not ok")
ok = false
debounce[Character] = false
detectLevel.Value = 5
break
end
until i == 0 or ok == false
if ok == true then
local reason = " got spotted by a citizen and raised the alarm!"
local plr = game.Players:FindFirstChild(Character.Name)
func:Fire(plr, reason)
debounce[Character] = false
end
end
end
end
end
end
end
end
end