Hi Devs, I’m making an horror game and I just wanted to know how to improve this code that makes fall a red block looking like blood dripping. I just want it to be more realistic
local lifetime = 1
while true do
wait(1.5)
local pos = script.Parent
local b = Instance.new("Part")
b.Position = pos.Position + pos.CFrame.lookVector
b.Size = Vector3.new(0.2, 1, 0.2)
b.formFactor = 2
b.Shape = 1
b.BrickColor=BrickColor.new("Bright red")
b.Transparency = .5
b.TopSurface = "Smooth"
b.BottomSurface = "Smooth"
b.CanCollide = false
b.Parent = game.Workspace
b.Velocity = Vector3.new(0, 0, 0)
game:GetService("Debris"):AddItem(b, lifetime)
end
It’d suggest using particles and cleaning a bit the code since its really kinda messy and basic. Like using a module script to store the data for the ParticleEmitter or Part.
I experimented and fixed up the code a little bit, but overall your code is really good.
while wait(1.5) do -- You can replace true with the delay
local pos = game.Workspace.Part -- I used a workspace part; you can change it back to script.Parent
local b = Instance.new("Part")
b.Position = pos.Position + pos.CFrame.lookVector
b.Size = Vector3.new(0.2, 1, 0.2)
b.formFactor = 2
b.Shape = 1
b.BrickColor = BrickColor.new("Bright red")
b.Transparency = .4 -- changed the transparency because it was too transparent
b.TopSurface = "Smooth"
b.BottomSurface = "Smooth"
b.CanCollide = false
b.Parent = game.Workspace
b.Velocity = Vector3.new(0, 0, 0)
game:GetService("Debris"):AddItem(b, 1) -- The lifetime variable wasn't used anywhere else
end
You could fix up this code a lot more. This is how I would do it
local Debris = game:GetService("Debris")
local pos = script.Parent -- you should refrain from giving inaccurate variable naming, consider changing its name
--[[
You really don't need to create a new part and set all the properties in a script.
You could simply just create a part, change its properties, put it in ReplicatedStorage, and index/clone it.
]]
local b = Instance.new("Part") -- You also don't really have to shorten this variable's name
b.Size = Vector3.new(0.2, 1, 0.2)
b.formFactor = 2
b.Shape = 1
b.BrickColor = BrickColor.new("Bright red")
b.Transparency = .5
b.TopSurface = "Smooth"
b.BottomSurface = "Smooth"
b.CanCollide = false
b.Parent = workspace
while true do
wait(1.5)
local ClonedPart = b:Clone()
ClonedPart.Position = pos.Position + pos.CFrame.lookVector
Debris:AddItem(b, 1)
end