How would I get rid of that first Instance.new part?

I am creating a wand and whenever I test it, without even equipping it there is a new part in the workspace. I made it so when you use the tool it creates a part but it isn’t working with no errors. Here is the script.

local FireBall = Instance.new("Part", game.Workspace)
tool = script.Parent
handle = tool:WaitForChild("Handle")
tool.Activated:Connect(function()
	FireBall.Shape = Enum.PartType.Ball
	FireBall.BrickColor = BrickColor.Red()
	FireBall.Size = Vector3.new(1, 1, 1)
	Instance.new("Fire", FireBall)
end)
tool.Unequipped:Connect(function()
	print("Deactivated")
	FireBall:Destroy()
end)

You are assigning the parent of the part before the tool has even been activated. Set the FireBall’s parent to workspace inside of the tool.Activated function.

2 Likes

When I do that I get the error [13:42:09.625 - Players.SadWowow21.Backpack.Wand.Script:12: attempt to index nil with ‘Destroy’]

1 Like

Keep the FireBall variable outside but remove the second argument to set the parent.

After you’ve assigned all of the properties in the Activated function to the Instance set the parent to workspace.

FireBall.Parent = game.Workspace
2 Likes

I’m a bit confused, am I supposed to do this

local FireBall = Instance.new("Part", game.Workspace)
FireBall.Parent = game.Workspace
tool = script.Parent
handle = tool:WaitForChild("Handle")
tool.Activated:Connect(function()
	FireBall.Shape = Enum.PartType.Ball
	FireBall.BrickColor = BrickColor.Red()
	FireBall.Size = Vector3.new(1, 1, 1)
	Instance.new("Fire", FireBall)
end)
tool.Unequipped:Connect(function()
	print("Deactivated")
	FireBall:Destroy()
end)
1 Like

You’re supposed to do this:

local FireBall = Instance.new("Part")
tool = script.Parent
handle = tool:WaitForChild("Handle")
tool.Activated:Connect(function()
	FireBall.Shape = Enum.PartType.Ball
	FireBall.BrickColor = BrickColor.Red()
	FireBall.Size = Vector3.new(1, 1, 1)
	Instance.new("Fire", FireBall)
    FireBall.Parent = game.Workspace
end)
tool.Unequipped:Connect(function()
	print("Deactivated")
	FireBall:Destroy()
end)
2 Likes

I get [13:51:35.936 - The Parent property of Part is locked, current parent: NULL, new parent Workspace] when I do that, but it works for the first one

1 Like

Change .Activated to .Equipped

2 Likes

that would only change it to when the tool is equipped though?

1 Like

My bad, try this:

tool = script.Parent
handle = tool:WaitForChild("Handle")
tool.Activated:Connect(function()
    FireBall = Instance.new("Part")
	FireBall.Shape = Enum.PartType.Ball
	FireBall.BrickColor = BrickColor.Red()
	FireBall.Size = Vector3.new(1, 1, 1)
	Instance.new("Fire", FireBall)
    FireBall.Parent = game.Workspace
end)
tool.Unequipped:Connect(function()
	print("Deactivated")
	FireBall:Destroy()
end)
2 Likes

Thanks! But do you think I should add a debounce or something to make it so people can’t spam it?

2 Likes