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

Why won't my cannonball script make the cannon shoot?

Asked by 7 years ago

I wanted to make my first minigame, but it doesn't seem to work. It's supposed to have cannons on one side shoot at the players on a bridge to knock them off, but it doesn't even shoot. This is what I'm using:

local Cannon = script.Parent
local CannonBody = Cannon.Union
local Cannonball = game.Workspace.Cannonball
local Wall = game.Workspace.Wall
local GameStart = false
local x = 13
local y = 5.312
local z = -62.5

if GameStart == true then
    local Clone = Cannonball:Clone()
    Clone.Position = Vector3.new(x, y, z)
    wait(1)
    Clone.Position = Vector3.new(x, y + 1, z + 1)
    if Wall.Touched == true then
        Clone:Destroy()
    end
end
wait(10)
GameStart = true

What can I do to fix this? Any help is appreciated!

0
You checked if GameStart is true but, at the beginning you declared it as true. KingLoneCat 2642 — 7y
0
As false* KingLoneCat 2642 — 7y
0
You need a function, not an if statement, on line 10. The if statement says, "If GameStart is currently true, then do these actions", not "When GameStart becomes true, do these actions". Turn it into a function and call it instead of "GameStart = true". Likewise, on line 15 you need an event, not an if statement. chess123mate 5873 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Hayo! The issue you have is pretty simple to fix. You set the GameStart to false at the start, then test if it's true. It only happens once at the start of the script. You could have a function that calls it or do a while wait() do. Here's my run of it.

local Cannon = script.Parent
local CannonBody = Cannon.Union
local Cannonball = game.Workspace.Cannonball
local Wall = game.Workspace.Wall
local GameStart = false
local x = 13
local y = 5.312
local z = -62.5

function cannonFire()
 if GameStart == true then
    local Clone = Cannonball:Clone()
    Clone.Position = Vector3.new(x, y, z)
    wait(1)
    Clone.Position = Vector3.new(x, y + 1, z + 1)
    if Wall.Touched == true then
        Clone:Destroy()
    end
 end
end
wait(10)
GameStart = true
cannonFire()

You can remotely trigger the function using RemoteEvents [for FilteringEnabled] or bindableEvents.

I personally prefer RemoteEvents. You can learn about them here, http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions

To properly implement a RemoteEvent, you can add,

script.RemoteEvent.OnServerEvent:Connect(cannonFire)

to the end of the script.

Hope I helped. :)

0
I did exactly what you told me to do, but it's still not working. Thanks anyways! marioblast1244 113 — 7y
0
Also, the RemoteEvent part is super confusing! Can you break it down for me? marioblast1244 113 — 7y
Ad

Answer this question