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!
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. :)