local Cannon = game.workspace.Cannon
local action = game.workspace.Action
local sp= script.Parent
local action=sp:WaitForChild("action")
function FireCannon()
local Ball = Instance.new("Part")
Ball.Name = "Effect"
Ball.Shape= "Ball"
Ball.Material= "Concrete"
Ball.Size=Vector3.new(3,3,3)
Ball.CanCollide=false
Ball.Cframe = Cannon.Cframe
Ball.Velocity = Cannon.Cframe.lookvector*50
Ball.TopSurface="Smooth"
Ball.BottomSurface="Smooth"
Ball.Parent= game.Workspace
script.parent.part.Onclicked:connect (FireCannon)
Ball.Position = Cannon.Position
end
while true do
wait()
FireCannon()
end
Cannon script, wont work? ball wont even show up
1 answer
I think this might fix the problem:
local Cannon = game.workspace.Cannon
local sp= script.Parent
local Action=sp:WaitForChild("ClickDetector")
function FireCannon()
local Ball = Instance.new("Part", game.Workspace)
Ball.Name = "Effect"
Ball.Shape= "Ball"
Ball.Material= "Concrete"
Ball.Size=Vector3.new(3,3,3)
Ball.CanCollide=false
Ball.CFrame = Cannon.CFrame
Ball.Velocity = Cannon.CFrame.lookVector*50 --You might want to make this a larger number
Ball.TopSurface="Smooth"
Ball.BottomSurface="Smooth"
Ball.Position = Cannon.Position
Ball.Touched:connect(function(Part)
if Part~=Cannon then
local Ex=Instance.new("Explosion",game.Workspace)
Ex.Position=Ball.Position
Ball:remove()
end
end)
end
Action.MouseClick:connect (FireCannon)
while true do --Remove this "while" loop if you want it to only fire when you click the part.
wait()
FireCannon()
end
Ok, so you basically had a lot of minor spelling errors. I think I should have fixed all or most of it. Make sure that there is a ClickDetector inside of the scripts parent, and that it's name is "action". Make sure that there is also a "Cannon" in the Workspace. If you have done all of this correctly, then it should work (I tested it also)
Also, I've added this little bit of code I think might help a bit with what your trying to accomplish:
Ball.Touched:connect(function(Part)
if Part~=Cannon then
local Ex=Instance.new("Explosion",game.Workspace)
Ex.Position=Ball.Position
Ball:remove()
end
end)
This basically just finds when the ball was hit by anything besides the cannon, then makes an explosion and removes the ball. If you do want to add it, add it in at the end of the FireCannon() function that you have. It should work fine.
Anyways, if you have any problems or questions, please leave a comment below. Hope I helped :P
6 comments
still doesn't work for some odd reason
Just make sure you read everything I put carefully, and do exactly what it said in my answer. If you did everything like I said to, idk why it wouldn't be working. I tested it myself to make sure it did work.
I'll try again.
maybe theres something wrong with my studio?
I highly doubt that. PM me on Roblox, and give me some more information, and we'll work out the bugs from there.
alright thanks
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
Edit your answer, click the Lua button, then paste your script between the lines. From there it will be easier for people to fix it.
Please put your code in lua code block format.
There @funyun please edit or help me if you can this is really irritating :/
@AthoronTheBrave Any errors?
Not really, its suppose to make the cannon fire a cannon ball but it does nothing
I think you just forgot to parent it into workspace, do this before adding velocity!