(SOLVED) Emit function not working properly unless delayed

So basically, I’ve scripted a tool so that if a player is holding it while clicking on the Zombie ragdoll, It will fire a remote and the script below handles it

  • The script works. However, the main issue I’m having here is that the emit functions don’t even emit anything. The catch is if I add “wait(0.1)” before, they will emit the particles

I don’t want any delay so “wait(0.1)” is practically not a solution for me unless there are no other approaches. I appreciate any help if you’ve got any

(Script is server-sided and is located in ServerScriptService)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local GasCan = ServerStorage.GameStuff.Items:WaitForChild("GasCan")

local BurnCorpseEvent = ReplicatedStorage.Remotes:FindFirstChild("BurnCorpseEvent")

BurnCorpseEvent.OnServerEvent:Connect(function(Player, Corpse)
	local Humanoid = Corpse:FindFirstChild("Zombie")

	if Humanoid then
		local burnsoundthingy = Instance.new("Sound")
		burnsoundthingy.SoundId = "rbxassetid://7978512250"
		burnsoundthingy.Volume = 1
		burnsoundthingy.PlayOnRemove = true
		burnsoundthingy.Parent = Corpse:FindFirstChild("HumanoidRootPart")
		
		local fireeff = script.Fire:Clone()
		fireeff.Parent = game.Workspace
		fireeff.Position = Corpse:GetPivot().Position
		local fire = fireeff.Attachment
		--wait(0.1) i dont want this 
		fire["1"]:Emit(20)
		fire["2"]:Emit(20)
		fire["3"]:Emit(20)
		fire["4"]:Emit(20)
		fire["5"]:Emit(20)
		game.Debris:AddItem(fireeff, 3)
		
		local gas = GasCan:Clone()
		gas.Parent = game.Workspace
		gas.Position = Corpse:GetPivot().Position

		Corpse:Destroy()
	end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local GasCan = ServerStorage.GameStuff.Items:WaitForChild("GasCan")

local BurnCorpseEvent = ReplicatedStorage.Remotes:FindFirstChild("BurnCorpseEvent")

BurnCorpseEvent.OnServerEvent:Connect(function(Player, Corpse)
	local Humanoid = Corpse:FindFirstChild("Zombie")

	if Humanoid then
		local burnsoundthingy = Instance.new("Sound")
		burnsoundthingy.SoundId = "rbxassetid://7978512250"
		burnsoundthingy.Volume = 1
		burnsoundthingy.PlayOnRemove = true
		burnsoundthingy.Parent = Corpse:FindFirstChild("HumanoidRootPart")
		
		local fireeff = script.Fire:Clone()
		fireeff.Parent = game.Workspace
		fireeff.Position = Corpse:GetPivot().Position
		local fire = fireeff.Attachment

        for i = 1, 5 do 
		    fire[tostring(i)]:Emit(20)
            task.wait()
        end
        game.Debris:AddItem(fireeff, 3)
		
		local gas = GasCan:Clone()
		gas.Parent = game.Workspace
		gas.Position = Corpse:GetPivot().Position

		Corpse:Destroy()
	end
end)
1 Like

Thanks! I tried using task.wait() before and It didn’t work but this time It does for some reason. And also thanks for rewriting that 1,2,3,4,5 part as well, I was a bit lazy

1 Like