I made a gate that lights up red when someone is carrying a blacklisted item, but green if not. The script is super simple and my model is open-sourced!
-
When carrying a blacklisted item
Gate Testing - Roblox Studio (gyazo.com) -
When carrying something else
Gate Testing - Roblox Studio (gyazo.com)
Gate it self
(1) Gate - Roblox
Gate.rbxm (4.7 KB)
Uncopylocked Testing place
Editing the code
local BadColor = Color3.new(1, 0, 0) --the color of the lights when carrying a blaclisted item
local GoodColor = Color3.new(0.333333, 1, 0) --the color of lights when carrying an non-blacklisted item
local NeutralColor = Color3.new(1, 1, 1) --the color of the lights when on standby
local BlacklistedNames = { --Edit the contents to the names of items you want to blacklist
"Tool",
"Tool2"
}
local Blacklisted = {}
for _, name in pairs(BlacklistedNames) do
Blacklisted[name] = true
end
function NameCheckFromTable (Table, Name)
return Table[Name]
end
function InstanceTableCheckWithStringTable (InstanceTable, StringTable)
for _, Item in pairs(InstanceTable) do
if StringTable[Item.Name] then
return true
end
end
return false
end
function LightUp (Color)
local Lights = script.Parent.Lights:GetChildren()
for i,item in pairs(Lights) do
item.Color = Color
end
end
function StartCheck (Touched)
local Char = Touched.Parent
local Player = game.Players:GetPlayerFromCharacter(Char)
if not Player then return end
local Backpack = Player.Backpack:GetChildren()
local HeldItem = Char:FindFirstChildOfClass("Tool")
local InsCheck = InstanceTableCheckWithStringTable(Backpack, Blacklisted)
local NameCheck = false
if HeldItem then
NameCheck = Blacklisted[HeldItem.Name]
end
local NewColor
if InsCheck or NameCheck then
NewColor = BadColor
else
NewColor = GoodColor
end
LightUp(NewColor)
wait(1)
LightUp(NeutralColor)
end
script.Parent.Sensor.Touched:Connect(StartCheck)
Editing the lights
- There will be a folder in the model called
Lights
, Inside there will be parts, any part that is inside will change colour to the different situation.
Updates
- Update 17/12/2020
Thanks to @goldenstein64, my code has been optimized!
Also, I made the testing place available to all. - Update 18/12/2020
Minor Update allowing more customization! (See “Editing the code”)
Feel free to give feedback!