How could I fix this particle emitter script


Text Form

local R6 = game.Workspace.R6
local HRMP = R6:WaitForChild("HumanoidRootPart")
local Attachment = HRMP:WaitForChild("Attachment")
local AttchmentClone = Attachment:Clone()
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(Input,Proc)
	if Proc then return end
	
	if Input.KeyCode == Enum.KeyCode.Z then
		AttchmentClone.Parent = player.Character:WaitForChild("HumanoidRootPart")
		player.Character:WaitForChild("Humanoid").WalkSpeed = 32
		wait(5)
		game:GetService("Debris"):AddItem(AttchmentClone,0)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 16
	end
	
	
end)

This bug happens when I press Z a second time after it was destroyed (And if your wondering I already used Attachment:Destroy

After a while of not parenting the Attachment clone, it becomes GC’d(garbage collected) and therefore have its Parent property locked. Only clone during execution, not in declaration.

The script wont run as written on my system. It starts then goes back to code view and stops.

I moved the line local AttchmentClone = Attachment:Clone() inside the function and now it runs and works.

local R6 = game.Workspace.R6
local HRMP = R6:WaitForChild("HumanoidRootPart")
local Attachment = HRMP:WaitForChild("Attachment")
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(Input,Proc)
	if Proc then return end

	if Input.KeyCode == Enum.KeyCode.Z then
		local AttchmentClone = Attachment:Clone()
		AttchmentClone.Parent = player.Character:WaitForChild("HumanoidRootPart")
		player.Character:WaitForChild("Humanoid").WalkSpeed = 32
		wait(5)
		game:GetService("Debris"):AddItem(AttchmentClone,0)
		player.Character:WaitForChild("Humanoid").WalkSpeed = 16
	end


end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.