so recently ive been improving my CKIT, and got a Killbrick script to manage all killbricks.
But that was using game.World.Each… which this also uses… Query is included.
I’ve improved the script a lot since i first posted it here, now i wanna share it with you all!
Make sure to credit me if you do use this script though.
Here’s the ButtonHandler of my CKIT! Manage all those pesky buttons with one script.
-- man Jediweirdo is a hero! made by Cva!
local Buttons = game.World.Query(game.World.Pair("Tag", "ButtonObject"))
local ButtonOrigin = {}
local ButtonDeactivators = game.World.Each(game.World.Pair("Tag", "ButtonDeactivator"))
local ButtonActivatedParts = game.World.Each(game.World.Pair("Tag", "ButtonActivatedPart"))
local isInitialized = false
local function ActivateParts(Color)
for i in ButtonActivatedParts do
local IColor = i.attr.ColorOverride or i.Color
local PTrans = 0
if IColor == Color or Color == false then
if i.attr.Invert then
PTrans = 0.5
if i.attr.FullHide then
PTrans = 1
end
end
--i:AddComponent("Transparency")
--i:AddComponent("Collider")
i.Transparency = i.attr.SetTransparency or PTrans
i.Collider = i.attr.Invert and "None" or "Auto"
end
end
end
local function DeactivateParts(Color)
ButtonActivatedParts = game.World.Each(game.World.Pair("Tag", "ButtonActivatedPart"))
for i in ButtonActivatedParts do
local IColor = i.Color
local PTrans = 0.5
if i.attr.ColorOverride then
IColor = i.attr.ColorOverride
end
if IColor == Color or Color == false then
if i.attr.FullHide then
PTrans = 1
end
if i.attr.Invert then
PTrans = 0
end
i.Collider = i.attr.Invert and "Auto" or "None"
i.Transparency = i.attr.IgnoreTransparency or PTrans
end
end
end
local function ButtonAlter(ButtonObject, Origin, Material)
local Button = ButtonObject:GetHandle('Button')
if Origin == false then
Button.Position += Button:TransformDirection(Vector3.new(0,-0.5,0))
else
Button.Position = Origin
end
Button.Material = Material or "Neon"
end
local function DeactivateButtons(Color)
for I = 1, Buttons.count do
local ButtonObject = Buttons.Instance[I]
local Button = ButtonObject:GetHandle('Button')
local ButtonColor = Button.Color
local O = Buttons.Instance[I]:GetHandle("Properties")
if not O then
warn(ButtonObject,"ButtonObject is missing a Properties Handle!")
O = ButtonObject
end
local ButtonTimer = O:FindFirstChild("ButtonTimer")
if ButtonObject.attr.Pressed == true and ButtonColor == Color or Color == false then
if ButtonTimer then
if ButtonTimer:HasComponent("TimerRunning") then
ButtonTimer:RemoveComponent("TimerRunning")
print("ButtonTimer Disconnected!")
end
end
ButtonAlter(ButtonObject, ButtonOrigin[I], "SmoothPlastic")
DeactivateParts(Color)
end
end
end
print("RUNNING")
function Update()
if isInitialized ~= true then
Buttons:Refresh()
for I = 1, Buttons.count do
local Button = Buttons.Instance[I]:GetHandle('Button')
local ButtonObject = Buttons.Instance[I]
ButtonOrigin[I] = Button.Position
local Color = Button.Color
local O = Buttons.Instance[I]:GetHandle("Properties")
if not Button or not O then
if not O then
warn(ButtonObject, "is missing Properties")
O = ButtonObject
else
warn("Critical Error,", ButtonObject, "will not work due to lack of Button")
end
end
local ColorSensitive = O.attr.ColorSensitive
if not ColorSensitive then
Color = false
end
local ButtonTimer = O:FindFirstChild("ButtonTimer")
Button.Touched:Connect(function(hit: Instance)
print(hit.Name,"touched button")
if Button.Material ~= "Neon" then
ButtonActivatedParts = game.World.Each(game.World.Pair("Tag", "ButtonActivatedPart"))
ButtonObject.attr.Pressed = false
end
if hit:HasComponent("BodyPart") == true and ButtonObject.attr.Pressed ~= true and O.attr.AcceptPlayers then
ButtonAlter(ButtonObject, false)
ButtonObject.attr.Pressed = true
ActivateParts(Color)
if ButtonTimer then
ButtonTimer:AddComponent("TimerRunning")
end
elseif hit:HasComponent(game.World.Pair("Tag", "Pushbox")) and ButtonObject.attr.Pressed ~= true and O.attr.AcceptPushbox and hit.Color == Color then
ButtonAlter(ButtonObject, false)
ButtonObject.attr.Pressed = true
ActivateParts(Color)
if ButtonTimer then
ButtonTimer:AddComponent("TimerRunning")
end
elseif hit:HasComponent(game.World.Pair("Tag", "Pushbox")) and ButtonObject.attr.Pressed ~= true and O.attr.AcceptPushbox and O.attr.BoxColorIgnore then
ButtonAlter(ButtonObject, false)
ButtonObject.attr.Pressed = true
ActivateParts(Color)
if ButtonTimer then
ButtonTimer:AddComponent("TimerRunning")
end
else
warn("Cant find it! / Pressed / Not accepted! / Didn't match!")
end
end)
if ButtonTimer then
ButtonTimer.Timeout:Connect(function()
ButtonAlter(ButtonObject, ButtonOrigin[I], "SmoothPlastic")
DeactivateParts(Color)
ButtonTimer:RemoveComponent("TimerRunning")
print("ButtonTimer Ended!")
end)
end
end
for i in ButtonDeactivators do
local Color = i.Color
local ColorSensitive = i.attr.ColorSensitive
if not ColorSensitive then
Color = false
end
i.Touched:Connect(function(hit: Instance)
if hit:HasComponent("BodyPart") == true then
DeactivateButtons(Color)
else
warn("Cant find character!")
end
end)
isInitialized = true
end
end
end
i am not to be held liable for any ghost parts that appear due to the ButtonHandler.
thanks @Jediweirdo for inspiring me to make this script.