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