Hey! So I’m using a script that makes blood drops when a player is damaged. The script is a server script so everything is controlled by one script. I want to use this same effect for the enemies in my game and keep using only one script. Is there a way to check if a Humanoid or a NPC has been added to the workspace or a folder. Something like when using PlayerAdded
I tried looking around for a solution but couldn’t find something that was similar enough to my issue.
(I didn’t make this script I used a YouTube tutorial)
local HealthPerDrop = 7
local DropLifeTime = 3.5
local DropSizeMin, DropSizeMax = 0.1, 2.4
local Blood = script:WaitForChild("Blood")
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
local PreviousHealth = hum.Health
hum.HealthChanged:Connect(function(NewHealth)
local HealthDif = PreviousHealth - NewHealth
PreviousHealth = NewHealth
if HealthDif < 0 then return end
local NumOfDrops = math.floor(HealthDif/ HealthPerDrop)
local DropsFolder = Instance.new("Folder", workspace)
for i = 1, NumOfDrops do
local DropSize = math.random(DropSizeMin * 10, DropSizeMax * 10) / 10
local BloodDrop = Blood:Clone()
BloodDrop.Size = Vector3.new(0,0,0)
local xPos = char.HumanoidRootPart.Position.X + math.random(-30,30) / 10
local yPos = char.HumanoidRootPart.Position.Y - char:WaitForChild("Left Leg").Size.Y/2 + 0.05
local zPos = char.HumanoidRootPart.Position.Z + math.random(-30,30) / 10
BloodDrop.Position = Vector3.new(xPos, yPos, zPos)
BloodDrop.Parent = DropsFolder
tweenservice:Create(BloodDrop, tweeninfo, {Size = Vector3.new(0.05, DropSize, DropSize)}):Play()
end
wait(DropLifeTime)
DropsFolder:Destroy()
end)
end)
end)