I apologize in advance for the script I'm going to present for this question, it's long.
Hi, I'm trying to get it so a cannon in my game will be able to shoot using a button in a GUI versus a physical button in the game.
The Script I tried using:
local gunBarrelOne = workspace.MediumBoat.cannonRR.GunBarrel.One
local debounce = false
local gunOne = true
local cannonBall = Instance.new("Part")
cannonBall.Size = Vector3.new(1,1,1)
cannonBall.BrickColor = BrickColor.new(26)
cannonBall.Shape = 0
cannonBall.BottomSurface = 0
cannonBall.TopSurface = 0
cannonBall.Name = "Cannon Shot"
cannonBall.Elasticity = .1
cannonBall.Reflectance = 0
cannonBall.Friction = 0
game.StarterGui.seatgui.Frame.switch1.MouseButton1Click:connect(fire)
function fire(player)
local sound = workspace.MediumBoat.cannonRR.Switch:findFirstChild("GunSound")
if sound == nil then
sound = Instance.new("Sound")
sound.Name = "GunSound"
sound.SoundId = "http://www.roblox.com/asset?id=2101148"
sound.Volume = 1
sound.Parent = workspace.MediumBoat.cannonRR.Switch
end
sound:play()
local missile = Instance.new("Part")
local barrel
if gunOne == true then
barrel = gunBarrelOne
gunOne = true
end
local spawnPos = barrel.CFrame * Vector3.new(6, 0, 0)
local dx = math.random(0,0)
local dy = math.random(0,0)
local dz = math.random(30,30)
local mag = math.random(200,200)
local v = barrel.CFrame:vectorToWorldSpace(Vector3.new(mag + dx,dy,dz))
local missile = cannonBall:clone()
missile.Position = spawnPos
missile.Velocity = v
local new_script =workspace.MediumBoat.cannonRR.Switch.CannonBall:clone()
new_script.Disabled = false
new_script.Parent = missile
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = missile
missile.Parent = game.Workspace
end

1 comment
What is the problem? Do you get an error?