game.Workspace:GetChildren() Keeps getting Camera which causes Script to break

game.Workspace:GetChildren() Keeps getting Camera which causes Script to break.

I am attempting to make a script which locates every part/mesh in the game and creates an explosion at that parts position.

Here is an error message I get:

image

I do not want to get all instances E.g: Camera. I only want to get parts/meshes.

Here is my code:

local assetid = 6005200754
game.Players.PlayerAdded:connect(function(player)
local MarketplaceService = Game:GetService('MarketplaceService')
--THE ABOVE IS IRRELEVENT
script.Parent.ProximityPrompt.Triggered:Connect(function(player)	
if MarketplaceService:PlayerOwnsAsset(player, assetid) then	
script.Parent.ProximityPrompt.Enabled = false			
script.Parent.Parent.other.ProximityPrompt.Enabled = false		
workspace.UhOh:Play()
wait(0.5)
workspace.Bang:Play()		
local e = Instance.new("Explosion")
local children = game.Workspace:GetChildren()			
for i = 1, #children do		
local child = children[i]			
e.BlastRadius = 50
e.BlastPressure = 60000000
e.Parent = child
e.Position = child.Position			
end			
wait(5)
script.Parent.ProximityPrompt.Enabled = true
else
game:GetService("MarketplaceService"):PromptPurchase(player, assetid)	
end		
end)
end)

Anybody know what I need to add in order to stop getting the Camera instance please?
Thanks :grinning:

1 Like

Adding in an if statement should solve your problem. Here’s what it looks like:

local assetid = 6005200754
game.Players.PlayerAdded:connect(function(player)
local MarketplaceService = Game:GetService('MarketplaceService')
--THE ABOVE IS IRRELEVENT
script.Parent.ProximityPrompt.Triggered:Connect(function(player)	
if MarketplaceService:PlayerOwnsAsset(player, assetid) then	
script.Parent.ProximityPrompt.Enabled = false			
script.Parent.Parent.other.ProximityPrompt.Enabled = false		
workspace.UhOh:Play()
wait(0.5)
workspace.Bang:Play()		
local e = Instance.new("Explosion")
local children = game.Workspace:GetChildren()			
for i = 1, #children do		
local child = children[i]
if child:IsA("BasePart") then <---		
e.BlastRadius = 50
e.BlastPressure = 60000000
e.Parent = child
e.Position = child.Position
end <---			
end			
wait(5)
script.Parent.ProximityPrompt.Enabled = true
else
game:GetService("MarketplaceService"):PromptPurchase(player, assetid)	
end		
end)
end)
3 Likes

It seems to only work once when you activate the button.

EDIT: Nevermind, I just had to add a “while true do” line to it and change up some of the code.
Thanks!

2 Likes