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)
Try adding a NumberValue called y under your button part, and then set its value to 0, then use this code. Lua seems weird about changing variables in while statements and it is still a mystery to me, but adding values into the workspace always seems to fix it.
local hit = script.Parent.Touched:Connect(function(hit) local y = script.Parent.y local position = script.Parent.Position local prevy = position.Y script.Parent.Touched:Connect(function(hit) script.Parent:WaitForChild("TouchInterest"):Destroy() if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then script.Parent.Material = Enum.Material.SmoothPlastic while y.Value < 0.5 do script.Parent.CFrame = CFrame.new(position.X,position.Y - y.Value,position.Z) wait(0.01) y.Value += 0.02 end end end) end)