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

How do I make a blood puddle when someone gets hurt? [closed]

Asked by 10 years ago

As in Catching Fire when you get hurt a blood puddle forms until the map clears I want that but I want it so it goes away after 1 minute.

Closed as Not Constructive by evaera

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Andalf 100
10 years ago

First of all create a localscript and put it in the player, once you've done that set up an anonymous function to fire when the humanoid takes damage.

local hum = script.Parent.Humanoid
local LastHealth = hum.Health
local maxSize = 5 -- Determines the maximum size of the blood pool

script.Parent.Humanoid.HealthChanged:connect(function(Health)
    local change = math.abs(LastHealth - Health) -- this will let us create a bloodpool proportional to the change ofHealth
    if LastHealth > Health then
        local Pool = Instance.new("Part", game.Workspace) -- creates the new part and sets it's values
        Pool.Anchored = false
        Pool.BrickColor = BrickColor.new("Bright red")
        Pool.FormFactor = "Custom"
        Pool.Size = Vector3.new((change/hum.MaxHealth)*maxSize, 0.2, (change/hum.MaxHealth)*maxSize) --Defined maxSize on Line 3 of the script, make it what ever you want. 
        Pool.TopSurface = "Smooth"
        Pool.BottomSurface = "Smooth"
        Pool.CFrame = CFrame.new() + script.Parent.Torso.CFrame * Vector3.new(0, -3, 0) -- should place it below the players feet.
        --Optional add a mesh here to make it round.
        Pool.CanCollide = false;
        Pool.Touched:connect(function(hit)
            if not hit.Parent:FindFirstChild("Humanoid") then
                Pool.Anchored = true
            end
        end)
        Spawn(function()        -- spawns this function on a separate thread so it doesn't stall this one
            wait(60)
            Pool:Destroy() -- destroys the pool after 60 seconds.
        end)
    end
    LastHealth = Health -- sets LastHealth to Health so that next time the script runs change can be calculated correctly
end)

Try this out and see if it works :).

To make this work for all players add a script to the workspace, then add a localscript to that script with the disabled property checked. Add the above code to the localscript.

In the script use this code

game.Players.ChildAdded:connect(function(Player) -- fires when a player joins the game
    Player.CharacterAdded:connect(function(Character) -- fires when it's character is added
        local poolScript = script.LocalScript:Clone() -- clones the localscript
        poolScript.Parent = Character -- parents it to the character
        poolScript.Disabled = false -- enables it
    end)
end)

What this will do is clone the localscript containing the pool code into each of the players characters when they join the game and whenever they respawn.

EDIT: So I've compiled the localscript at the top for you, it's in one part now.

Layout in Explorer:
Workspace
-Script (2nd codeblock goes here)
--LocalScript (1st codeblock goes here)
0
I'm new to scripting how exactly do I set up the anonymous function and stuff like that XD paulieD123 5 — 10y
1
put a script in the humanoid and copy and paste the code, just make sure to read the comments ( the green text after two dashes) and try and understand what it's doing. Andalf 100 — 10y
0
What if I want it to affect everyone not just the humanoid paulieD123 5 — 10y
1
you put this in the players when they join the game Andalf 100 — 10y
View all comments (12 more)
0
So in the players tab of explorer? paulieD123 5 — 10y
1
sort of, I'll update my answer with an explanation. Andalf 100 — 10y
1
Updated Andalf 100 — 10y
0
oh okay thx C: paulieD123 5 — 10y
0
I tried it and it didn't work can u combine the 1st 2 into 1 for me I'm new at this XD paulieD123 5 — 10y
0
I'll fix it up and put it together for you, I included a few typos, I'll let you know when it's updated. Andalf 100 — 10y
0
thanks paulieD123 5 — 10y
0
done Andalf 100 — 10y
0
thanks paulieD123 5 — 10y
0
Still didn't work :C what exactly is the code block i might've been missing that paulieD123 5 — 10y
0
That's just the block of code shown above, if you click the icon on the top right corner of it when you hover your mouse over it, you can copy it all. Andalf 100 — 10y
0
Yeah I did that and it still didn't work :C paulieD123 5 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

When you script this, it would be a good idea to make it a function, then you can just call it every time someone dies :3

PS, i also play catching fire x3