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
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