So I have a scanner that checks for certain tools, such as weapons and tells the operator if they are armed or not on a textlabel. The scanner scans everyone in a room. It keeps saying my script bellow is attempting to call a nil value.
local Players = game:GetService("Players")
local armed = false
local text = script.Parent.SurfaceGui.TextButton.Text
local part = script.Parent
local function onTouched(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then
local Backpack = player.Backpack
print(player.Name)
armed = false
if Backpack:FindFirstChild("M4A1") then
armed = true
end
if Backpack:FindFirstChild("AK47") then
armed = true
end
if Backpack:FindFirstChild("Baton") then
armed = true
end
if Backpack:FindFirstChild("Pistol") then
armed = true
end
if Backpack:FindFirstChild("Rifle") then
armed = true
end
if armed == true then
text = "ARMED"
else
text = "UNARMED"
end
end
end
part.Touched:Connect(onTouched)
