Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cannon script, wont work? ball wont even show up

Asked by 9 years ago
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
0
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. funyun 958 — 9y
0
Please put your code in lua code block format. Goulstem 8144 — 9y
0
There @funyun please edit or help me if you can this is really irritating :/ AthoronTheBrave 45 — 9y
0
@AthoronTheBrave Any errors? AmiracIe 175 — 9y
View all comments (2 more)
0
Not really, its suppose to make the cannon fire a cannon ball but it does nothing AthoronTheBrave 45 — 9y
0
I think you just forgot to parent it into workspace, do this before adding velocity! dragonkeeper467 453 — 9y

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

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

0
still doesn't work for some odd reason AthoronTheBrave 45 — 9y
0
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. dyler3 1510 — 9y
0
I'll try again. AthoronTheBrave 45 — 9y
0
maybe theres something wrong with my studio? AthoronTheBrave 45 — 9y
View all comments (2 more)
0
I highly doubt that. PM me on Roblox, and give me some more information, and we'll work out the bugs from there. dyler3 1510 — 9y
0
alright thanks AthoronTheBrave 45 — 9y
Ad

Answer this question