Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I define nothigness in player's backpack?

Asked by 4 years ago

So basically, I've made a script that checks for contraband after the player walks over a certain part. If found any contraband it triggers an alarm and a light turns red. If it found tools in player's backpack but none are named like the contrabands the light turns green and then yellow. If the player doesn't have any tools the light will remain yellow. How to make it so the light turns green even if the player has no tools? I was trying to use nil value but it didn't work for me.

local contraband = {
    "AK74M", 
    "USP",
}
local players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    local player = players:GetPlayerFromCharacter(hit.Parent)
    for i,v in pairs(player.Backpack:GetChildren()) do
        if table.find(contraband,v.Name) and script.Parent.Parent.Light.Sound.Playing == false then
            script.Parent.Parent.Light.BrickColor = BrickColor.new("Bright red")
            script.Parent.Parent.Light.Sound:Play()
        elseif not table.find(contraband,v.Name) and script.Parent.Parent.Light.Sound.Playing == false then
            script.Parent.Parent.Light.BrickColor = BrickColor.new("Lime green")
            wait(1)
            script.Parent.Parent.Light.BrickColor = BrickColor.new("Neon orange")
        end
    end
end)
0
use and else statement marine5575 359 — 4y
0
if the character has multiple items between contra and valid then it'll flash between colors lol Fifkee 2017 — 4y

Answer this question