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

How do you make your bodyparts fade on respawn?

Asked by 10 years ago

How do you make your bodyparts just fade away when you respawn?

0
Ok I edited the post! alessandro112 161 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

That's the code, I'll comment because it's too long to explain:

local charParts = {} -- We store every player's part here
local player = game.Players.LocalPlayer -- Defining the player value

function addPartToArray()
    -- For every part in the player's Character do....
    for _, part in pairs (player.Character:GetChildren()) do
        -- We don't need to fade non-concrete parts
        if tostring(part) == "Humanoid" or tostring(part) == "HumanoidRootPart" 
            or tostring(part) == "Sound" or tostring(part) == "Animate" then
            print("Skipping part" .. " " .. tostring(part))
        else
            table.insert(charParts, part) -- We insert the parts that we need to fade out
            print("Adding part" .. " " .. tostring(part)) -- Just for debugging :P
        end
    end
end

-- Every 0.01 the transparency of every part in the array "charParts" will fade by "0.1"
function fadeOut()
    while true do
        for _, part in pairs(charParts) do
            part.Transparency = part.Transparency + 0.1
            wait(0.01)
        end
    end
end

-- Since I don't know why in LocalPlayer the ".Death" method doesn't work, I made one on my own :P
function onDeath()
    while true do
        if player.Character.Humanoid.Health <= 0 then
            wait(0.1)
            fadeOut() -- I called here the fadeOut function
        end
        wait(0.2)
    end
end

addPartToArray() -- On player's character loads automatically add the parts to the array
onDeath() -- On the death they will fade out ;P

That should work, it has been tested! WARNING: Put this code in a LocalScript INSIDE the STARTERGUI!

Ad

Answer this question