Instance.new() not working

Hello!
I was trying to make a script that creates an “explosion” when touched.
But the Instance.new() is not working

Server script inside of a part:

local exploded = false

function touched(hit)
	if not exploded then
		exploded = true
		
		print("touched")

		local explosion = Instance.new("Part")
		
		explosion.Name = "explosion"

		explosion.Shape = Enum.PartType.Ball
		explosion.Color = Color3.new(1, 0.643137, 0.352941)

		explosion.Anchored = true
		explosion.Position = hit.Position
	end
end

script.Parent.Touched:Connect(touched)

“touched” prints inside dev console. this means I have a problem with the instance.new
Any help is appreciated.

Assuming you are trying to get the Instance Explosion: You are Creating a part, not an Explosion

local Debris = game:GetService("Debris")
script.Parent.Touched:Connect(function(hit)
local Hum = hit.Parent:FindFirstChild("Humanoid")

if Hum then
local Explosion = Instance.new("Explosion")
Explosion.Position = hit.Position
Debris:AddItem(Explosion, 3)
end
end)

OOPS

I misread, And i made a mistake, you arent putting the “Explosion” in the Workspace

So this:

local Debris = game:GetService("Debris")
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
	
local Explosion = Instance.new("Explosion", workspace)


		
		Explosion.Position = hit.Position
		Debris:AddItem(Explosion, 1.1)
end
end)

Make sure you add your Items into the workspace or into a Item IN the the workspace

No, i dont want to make an actual explosion. I am making a part that looks like one so it fits my games style.

This is all you need to read then

Alright. I will try it tomorrow. I am going to bed

You need to parent the instance that has been created.
For example Instance.new("Part", game.Workspace)

Hope this helps :slightly_smiling_face:

Already did that here in the Posts above

Yeah, I just forgot to parent the part to workspace. It was late at night and I was kinda dumb… lol

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