Hello, I am having trouble creating this script. I am trying to make it where if they player is holding down a key, the color of a brick gets darker and darker 4 shades the longer they hold it. However, if they release the key, the brick resets back to its default white color. Its not working correctly for me for some reason. Any ideas?
UserInputService = game:GetService("UserInputService")
local ZKeyPressed = false local building = game.Workspace.b1 local debounce = false local colortable = {game.Workspace.b1} colornumber = 0
UserInputService.InputBegan:Connect(function(input,gameProccesedEvent) if input.KeyCode == Enum.KeyCode.Z then if not debounce then debounce = true ZKeyPressed = true
end while ZKeyPressed == true do wait(0.5) colornumber = colornumber + 1 print("z pressd") for i, v in pairs(colortable)do if colornumber == 1 then wait(5) v.BrickColor = BrickColor.new("Pink") if colornumber == 2 then wait(5) v.BrickColor = BrickColor.new("Hot pink") if colornumber == 3 then wait(5) v.BrickColor = BrickColor.new("Magenta") if colornumber == 4 then wait(5) v.BrickColor = BrickColor.new("Eggplant") print(v) end end end end end end end
end)
UserInputService.InputEnded:Connect(function(input, gameProccesedEvent) if input.KeyCode == Enum.KeyCode.Z then ZKeyPressed = false do
print("z releaesed") debounce = false colornumber = 0 for i, v in pairs(colortable)do if colornumber == 0 then v.BrickColor = BrickColor.new("White") end end end end end)