In this code, the button will still be pressed and will glitch out of the world even after already being pressed, and also it looks horrible in game.
local hit = script.Parent.Touched:Connect(function(hit)
local y = 0.5
local touchedalready = false
local position = script.Parent.Position
local prevy = position.Y
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and touchedalready == false then
touchedalready = true
script.Parent.Material = Enum.Material.SmoothPlastic
while y > 0 do
script.Parent.CFrame = CFrame.new(position.X,position.Y - 0.02,position.Z)
wait(0.01)
y -= 0.02
print(touchedalready)
end
end
end)
end)

1 comment
Thank you, this is very important since my whole game is about buttons.