Hi ! I’ve recently tried to make an efficent blood system I don’t know if I did it the best way and I want to make my game as good as possible !
If any more experienced Roblox Scripter could review my script than I would be the happies man ! THANKS !
Only thing i considered changing is to use Module script and OOP instead of simple server script !
My Code:
local humanoid = script.Parent.Humanoid
function check(part)
print("checkling ")
local rayOrigin = script.Parent.Position
local rayDirection = (part.Position - script.Parent.Position).Unit * 30
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
print("results")
if raycastResult.Instance.Anchored == true then
local part = Instance.new("Part", script.Parent)
part.Anchored = true
part.Size = Vector3.new(0,0,0)
part.Shape = "Cylinder"
part.BrickColor = BrickColor.new("Maroon")
part.Material = Enum.Material.Glass
part.Reflectance = .2
part.CanQuery = false
part.CanTouch = false
part.CanCollide = false
part.Orientation = raycastResult.Instance.Orientation --- Vector3.new(0,90,0)
part.Position = raycastResult.Position
local Sscript = script["siye Changer"]:Clone()
Sscript.Parent = part
Sscript.Enabled = true
end
end
end
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
print("DEMAGE DETECTED")
for i, v in pairs(workspace:GetPartBoundsInRadius(Vector3.new(script.Parent.Position),100)) do
if v~= script.Parent then
check(v)
end
end
end)
The thing works by detecting the health change than getting all parts in a certain radius (adjustable) than calling a function called “check()”
and passing the part wich was detected than a quick raycast towards the parts position
if the ressult Instance is Anchored than a Cylined will spawn there !
Change any function to local if you can. This isn’t too big, but it’s a bit better. change it to
local function check
Another thing I saw was you used the parent parameter of Instance.new()
You can read more about it here:
Also, some of the variable names you use are a bit confusing, such as Sscript.
Im not too sure about this But I read somewhere that generalized iteration was faster than pairs or ipairs
The way you could change it to generalized iteration is like this:
for i, v in workspace:GetPartBoundsInRadius(Vector3.new(script.Parent.Position),100) do
One last thing I saw is that you clone the script and enabled it. If possible, I’d recommend doing whatever is in that script inside the script itself if it’s convenient.
Those are the only things I see that could be changed to be better, so good job!
Although this is probably not the “best” blood system, it is still a good one. You are not copying the material, so it will not be performance efficient. It is because you copy the script instead of the material.
Let’s say you want 100 blood decals. If you copy the script, you will have 100 scripts which is quite expensive.
If you copy the material, it is only once.