What I want to Achieve
Making a Cooldown for spawn(function()
The Script
local cleanuptime = 20 -- time when its gonna cleanup
function Raycast(origin, direction, ignorelist) -- we move raycasting to a function so the final function doesnt get long
local params = RaycastParams.new()
params.FilterDescendantsInstances = ignorelist
params.FilterType = Enum.RaycastFilterType.Blacklist
local Result = workspace:Raycast(origin, direction, params)
return Result
end
-- final function
function Splatter(c)
local ray = Raycast(c.HumanoidRootPart.Position, Vector3.new(0,-1,0) * 10, {c})
if ray then -- we check if there is a ray
-- there is a ray :D!
if ray.Instance then -- we check if hit something
-- it hit something!
for i = 1,math.random(2,4) do -- 1 splatter is kind of boring why not add more!
local splatter = game.ServerStorage.BloodSplatter:Clone() -- clone the splatter from serverstorage
splatter.Position = ray.Position + Vector3.new(math.random(1,3),0,math.random(1,3)) -- random position
splatter.Orientation = Vector3.new(0,math.random(10,90),0) -- random orientation
splatter.Parent = workspace -- now we parent it to the workspace)
spawn(function() -- appear & cleanup
-- tween service!
local tween = game:GetService("TweenService"):Create(splatter.BloodTop, TweenInfo.new(1, Enum.EasingStyle.Sine), {Transparency = 0.7})
tween:Play() -- makes the splatter appear
wait(cleanuptime) -- waits the cleanup time
local clean = game:GetService("TweenService"):Create(splatter.BloodTop, TweenInfo.new(5, Enum.EasingStyle.Sine), {Transparency = 1})
clean:Play()
clean.Completed:Connect(function()
splatter:Destroy() -- destroy the splatter when cleaning is done!
end)
end)
end
end
end
end
game.Players.PlayerAdded:Connect(function(P) -- when a player is added we...
P.CharacterAdded:Connect(function(C) -- when a character is added we...
C.Humanoid.HealthChanged:Connect(function()
Splatter(C)
end)
end)
end)
I’m not really a fan of scripting so I do not know what I am doing, I’ve tried putting wait(10) below the spawn(function() but Nothing Seems to work. A little help would be appreciated.
Script is stored at ServerScriptStorage and the Model is stored at ServerStorage