I've been working on my game lately Retro Wars which involves different weapons, vehicles, and buildings for warfare and I have just now started working on my plane that drops bombs. I would like to create the script myself for which drops bombs instead of trying to find a free-modeled version of what I'm trying to find. I'm a beginner at scripting and have been teaching myself for a while, so I know some things but not everything.
Problem: The script that I have made does not work and I don't know what I'm doing wrong in the script to make it not work. How the bomb spawner works is there is a click button, the parent of this script which also has the clickdetector in it. The parent of the script is called "bomber" and is inside a model with another part called "bombdoor". When the button is clicked with the mouse, a bomb is supposed to spawn and position itself automatically at the bombdoor then be dropped. When it hits an object, it is supposed to explode on contact.
function onClicked(bomber)
local bomb = Instance.new("Part")
local bombdoor = script.Parent.Parent.bombdoor
bomb.Position = bombdoor
bomb.Anchored = false
bomb.CanCollide = true
bomb.Locked = true
bomb.Size = 2,2,2
bomb.Shape = 0
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
function onTouched(hit, bomb)
if bomb == nil then return end
local blowup = Instance.new("Explosion")
local bombsound = Instance.new("Sound")
bombsound.SoundId = "rbxassetid://357562152"
blowup.BlastPressure = 300
blowup.BlastRadius = 40
blowup.Position = bomb.Position
blowup.Parent = game.Workspace
if bombsound then bombsound:Play()
bombsound.Position = bomb.Position
end
wait(.1)
if bomb then bomb:Remove() end
end
--missing the part that comes at the end of the function like line 12

1 comment
You create the bomb but do not add it to the workspace, e.g. bomb.Parent = game.Workspace, you can also add the parent to the instance.new as it is an optional paramater. You also need to add the touched event for the bomb.