Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --print("Hello, World!")
- local TweenService = game:GetService("TweenService") -- Perbaikan di sini: 'Local' menjadi 'local'
- local part = script.Parent -- Asumsikan script ditempel di part
- -- Konfigurasi animasi
- local RISE_HEIGHT = 25 -- Ketinggian naik (studs)
- local RISE_DURATION = 1.5 -- Durasi naik (detik)
- local FALL_DURATION = 1.5 -- Durasi turun (detik)
- local HOLD_TIME = 3 -- Waktu bertahan di atas (detik)
- local EASING_STYLE_UP = Enum.EasingStyle.Quad -- Gaya animasi naik
- local EASING_STYLE_DOWN = Enum.EasingStyle.Quad -- Gaya animasi turun
- local isAnimating = false -- Variabel debounce: true jika animasi sedang berjalan
- local debounceTime = 0.5 -- Waktu tunggu (detik) setelah animasi selesai sebelum bisa dipicu lagi
- local originalPosition = part.Position -- Simpan posisi awal
- local function riseBlock()
- if isAnimating then -- Jika sedang animasi, keluar dari fungsi
- return
- end
- isAnimating = true -- Set debounce menjadi true, menandakan animasi dimulai
- -- Hitung posisi baru
- local targetPosition = originalPosition + Vector3.new(0, RISE_HEIGHT, 0)
- -- Buat tween naik
- local tweenInfoUp = TweenInfo.new(
- RISE_DURATION,
- EASING_STYLE_UP,
- Enum.EasingDirection.Out
- )
- local riseTween = TweenService:Create(part, tweenInfoUp, {Position = targetPosition})
- riseTween:Play()
- -- Tunggu sampai selesai naik
- riseTween.Completed:Wait()
- -- Tunggu beberapa detik di atas
- task.wait(HOLD_TIME) -- Menggunakan task.wait()
- -- Buat tween turun
- local tweenInfoDown = TweenInfo.new(
- FALL_DURATION,
- EASING_STYLE_DOWN,
- Enum.EasingDirection.Out
- )
- local fallTween = TweenService:Create(part, tweenInfoDown, {Position = originalPosition})
- fallTween:Play()
- fallTween.Completed:Wait()
- -- Setelah animasi selesai, tunggu debounceTime sebelum reset isAnimating
- task.wait(debounceTime) -- Menggunakan task.wait()
- isAnimating = false -- Reset debounce, agar bisa dipicu lagi
- end -- Penutup fungsi riseBlock() perlu ada di sini, di akhir definisinya.
- part.Touched:Connect(function(hit)
- -- Cek jika player yang menyentuh DAN animasi tidak sedang berjalan
- if hit.Parent:FindFirstChild("Humanoid") and not isAnimating then
- riseBlock()
- end
- end)
- -- Optional: Buat part berwarna untuk visualisasi
- -- part.BrickColor = BrickColor.new("Bright blue") -- Dihapus agar warna asli part tetap
- part.Material = Enum.Material.Neon
- part.Anchored = true -- Pastikan anchored agar tidak jatuh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement