Help with doing Heart shaking effect on low health

Hello! i did health bar system for my game. Everything done about Health bar system but i want to do the heart shaking effect like this:

Sqta

So i don’t know how can i do that. I’ll be so glad if you guys can help me

Create tweens for every single heart and make the hearts go up and down, and randomly play the tweens with using math.random

I’m going to assume that every single heart is its own instance. Detecting when the player is at low health is easy: just reference the player’s character’s Humanoid and check its health: game.Players.LocalPlayer.Character.Humanoid.Health <= shakeThreshold

If the health is sufficiently low, just iterate through every heart and add a random value to its y-offset every time you want a heart to bump.

When I add wait() to :GetChildren() It’s doing the effect in queue.

1 Like

You could just randomy choose to wait or not. That will make certain adjacent hearts rise together. There are more sophisticated approaches but it’s not really noticable tbh

EDIT: You may want to consider moving multiple hearts at once

I don’t know, I’ll try something.

My approach? I’d store the hearts in an array and use some array math to select the next group of hearts to rise/lower together. That way, it’s uniformly random across the hearts and I have more control

  1. replace Wait() with task.wait()

  2. you can try using coroutines:

local thread = coroutine.create(function()

— place code here

end)

coroutine.resume(thread)

for this particular approach you can try:

for _, instance in pairs(Parent:GetChildren())

local thread = coroutine.create(function()

task.wait()

— place code here

end)

coroutine.resume(thread)

end)

Nevermind guys, i solved problem myself. Thx for helping

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.