Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Slowly fade blood onto the players screen as they take damage?

Asked by 3 years ago

I am trying to make a script that will slowly fade blood onto the players screen. The amount of blood shown will slowly increase the lower their health gets.

I started to attempt this myself, but the way I am doing it seems inefficient. Is there a better way other than manually stating the health values?

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local PlayerUI = Player:WaitForChild("PlayerGui")
local BloodEffect = PlayerUI:WaitForChild("ScreenEffects"):WaitForChild("Blood")

Character.Humanoid.HealthChanged:Connect(function(NewHealth)
    if NewHealth >= 80 and NewHealth <= 99 then
        for i = 0,.9,.05 do
            BloodEffect.ImageTransparency = i
            wait()
        end
    else if NewHealth >= 60 and NewHealth <= 79 then
            for i = 0,.7,.05 do
                BloodEffect.ImageTransparency = i
                wait()
            end
        end
    end 
end)
0
In situations like these I highly suggest using TweenService. Trust me, it is worth learning. I also would get the percentage of health to total health to do this. greatneil80 2647 — 3y
0
Do you need the for loops could you use direct values with UDim.new for BloodEffect.ImageTransparency? iamajunky 20 — 3y
0
I don't have an answer, but just know, your game may (or may not) get baned by roblox. just sayin... pugguy1000 3 — 3y

Answer this question