Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Lets try my blood script AGAIN?

Hello! I have been askign freqently about my script and actually figured most of it out on my own. I am making a blood script. I finnally got everything wrokign except 2 things:

  1. I don't know how to make the parts come out of the player's body.
  2. All the parts seem to be welded together. I need them to be all separated. I have the script inserted into the player already. Here is the script so far:
s = script.Parent

s.Humanoid.Died:connect (function ()
wait (0)
P1 = Instance.new("Part",game.Workspace)
P1.BrickColor = BrickColor.new("Bright red")
P1.FormFactor = 2
P1.Size = Vector3.new(1,0.4,1)
P1.CanCollide = true
P1.Anchored = false
P2 = Instance.new("Part",game.Workspace)
P2.BrickColor = BrickColor.new("Bright red")
P2.FormFactor = 2
P2.Size = Vector3.new(1,0.4,1)
P2.CanCollide = true
P2.Anchored = false
wait (0)
P3 = Instance.new("Part",game.Workspace)
P3.BrickColor = BrickColor.new("Bright red")
P3.FormFactor = 2
P3.Size = Vector3.new(1,0.4,1)
P3.CanCollide = true
P3.Anchored = false
P4 = Instance.new("Part",game.Workspace)
P4.BrickColor = BrickColor.new("Bright red")
P4.FormFactor = 2
P4.Size = Vector3.new(1,0.4,1)
P4.CanCollide = true
P4.Anchored = false
end)


3 answers

✓ Accepted answer

*This code was placed in a LocalScript in StarterGUI. In order to make the blood come out of the player's body, you must first make the blood's CFrame be the same as the player's torso/head. Also, the blood parts were sticking together because their surfaces were studs and inlets, and these two surfaces, when put together, MAKE A WELD. I fixed up everything for you below. :)

s = game.Players.LocalPlayer

s.Character.Humanoid.Died:connect(function()
	wait(0)
	
	local P1 = Instance.new("Part",game.Workspace)
	local P2 = Instance.new("Part",game.Workspace)
	local P3 = Instance.new("Part",game.Workspace)
	local P4 = Instance.new("Part",game.Workspace)
	
	P1.CFrame = CFrame.new(s.Character.Torso.Position)
	P2.CFrame = CFrame.new(s.Character.Torso.Position)
	P3.CFrame = CFrame.new(s.Character.Torso.Position)
	P4.CFrame = CFrame.new(s.Character.Torso.Position)
	
	P1.BottomSurface = "Smooth"
	P1.TopSurface = "Smooth"
	P2.BottomSurface = "Smooth"
	P2.TopSurface = "Smooth"
	P3.BottomSurface = "Smooth"
	P3.TopSurface = "Smooth"
	P4.BottomSurface = "Smooth"
	P4.TopSurface = "Smooth"
	
	P1.BrickColor = BrickColor.new("Bright red")
	P1.FormFactor = 2
	P1.Size = Vector3.new(1,0.4,1)
	P1.CanCollide = true
	P1.Anchored = false
	
	P2.BrickColor = BrickColor.new("Bright red")
	P2.FormFactor = 2
	P2.Size = Vector3.new(1,0.4,1)
	P2.CanCollide = true
	P2.Anchored = false
	wait (0)
	
	P3.BrickColor = BrickColor.new("Bright red")
	P3.FormFactor = 2
	P3.Size = Vector3.new(1,0.4,1)
	P3.CanCollide = true
	P3.Anchored = false
	
	P4.BrickColor = BrickColor.new("Bright red")
	P4.FormFactor = 2
	P4.Size = Vector3.new(1,0.4,1)
	P4.CanCollide = true
	P4.Anchored = false
end)



I hope this helps.

You never set the position of the blood parts. In this case it should suffice to simply position them at the same position as the torso.

P1.Position = script.Parent.Torso.Position

If this doesn't work out right, we can offset them a bit.

P1.Position = script.Parent.Torso.Position - Vector3.new(2,0,0)

It would also be much more clean and efficient to put that code inside a function, then calling that function four times. This way we don't have repeating code.

function createPart()
	local part = Instance.new("Part",game.Workspace)
	part.BrickColor = BrickColor.new("Bright red")
	part.FormFactor = 2
	part.Size = Vector3.new(1,0.4,1)
	part.CanCollide = true
	part.Anchored = false
	part.Position = script.Parent.Torso.Position
end

script.Parent.Humanoid.Died:connect(function()
	createPart()
	createPart()
	createPart()
	createPart()
end)

However, there is an even better way to do this. We can use parameters, arguments, and for loops to make the function create the specific amount of parts we want, without repeating code and without repeatedly calling it. This new method will also give us perfect control in case we want to create more or less parts at a specific time.

function createParts(numberOfParts)
	for i = 1, numberOfParts do
		local part = Instance.new("Part",game.Workspace)
		part.BrickColor = BrickColor.new("Bright red")
		part.FormFactor = 2
		part.Size = Vector3.new(1,0.4,1)
		part.CanCollide = true
		part.Anchored = false
		part.Position = script.Parent.Torso.Position
	end
end

script.Parent.Humanoid.Died:connect(function()
	createParts(4)
end)

1 comment

0

Thank you! I didn't know how to set the position to the body of the character. That was all I was missing! I used the same original script that I made but just added that for the sake of understanding it better.

Objects have a .Position or .CFrame property which is where they are located. It's better to place things with CFrame usually, because Position will behave not exactly as you expect.

The .CFrame property is (unsurprisingly) a CFrame value. You can just use the player's Torso's .CFrame value for it.

Possibly they are getting joined to each other or the Baseplate. Try adding a :BreakJoints() call to each of P1, P2, etc.

Since all of them are the same, and you're only using wait(0) you should use a loop.


for count = 1, 4 do
	local p = Instance.new("Part",game.Workspace)
	p.BrickColor = BrickColor.new("Bright red")
	p.FormFactor = 2
	p.Size = Vector3.new(1,0.4,1)
	p.CanCollide = true -- Redundant; Is default value.
	p.Anchored = false -- Redundant; Is default value
	p:BreakJoints()
	p.CFrame = s.Torso.CFrame
end

This discussion is preserved as it was. New answers, comments, and votes are closed.