I have a small problem, i would like to make a shuttle that shoots with a laser! found one but it does not work

firin = false

damage = 2

local gui = script.Parent:WaitForChild’gui’

function onB1D(mouse)

firin = true

while firin do

wait()

if mouse.Target.Parent ~= script.Parent.Vehicle.Value and mouse.Target.Parent.Parent ~= script.Parent.Vehicle.Value then

script.Parent.Vehicle.Value.Gun1.Fire:play()

local theTar = mouse.Hit.p

local bull = Instance.new(“Part”)

bull.Parent = game.Workspace

bull.CFrame = CFrame.new((theTar + script.Parent.Vehicle.Value.Gun1.Position)/2,script.Parent.Vehicle.Value.Gun1.Position)

bull.CanCollide = false

bull.BrickColor = BrickColor.new(“Bright yellow”)

bull.Material = Enum.Material.Neon

bull.Anchored = true

bull.Transparency = 0

bull.Size = Vector3.new(1,1.2,1)

local mesher = Instance.new(“BlockMesh”)

mesher.Parent = bull

mesher.Scale = Vector3.new(0.4, 0.4, (mouse.Hit.p - script.Parent.Vehicle.Value.Gun1.Position).magnitude)

local d = game:GetService(“Debris”)

d:AddItem(bull,0.05)

if mouse.Target.Parent.Parent.Name == “Pirate” or mouse.Target.Parent.Parent.Name == “FastPirate” or mouse.Target.Parent.Parent.Name == “TankPirate” or mouse.Target.Parent.Parent.Name == “CloakPirate” or mouse.Target.Parent.Parent.Name == “CarrierPirate” then

local case = mouse.Target.Parent.Parent:FindFirstChild’Parts’

if case then

if not case:FindFirstChild’Turret’ then return end

local hp = case.Turret:FindFirstChild’Health’

if hp and hp.Value > 0 then

hp.Value = hp.Value - damage

gg.dmg.Text = "HP: " … hp.Value

if hp.Value == 0 then gg:Destroy() end

if gg then gg.Sound:Play() end

end

end

end

wait(0.1)

end

if mouse.Target.Parent ~= script.Parent.Vehicle.Value and mouse.Target.Parent.Parent ~= script.Parent.Vehicle.Value then

script.Parent.Vehicle.Value.Gun2.Fire:play()

local theTar = mouse.Hit.p

local bull1 = Instance.new(“Part”)

bull1.Parent = game.Workspace

bull1.CFrame = CFrame.new((theTar + script.Parent.Vehicle.Value.Gun2.Position)/2,script.Parent.Vehicle.Value.Gun2.Position)

bull1.CanCollide = false

bull1.BrickColor = BrickColor.new(“Bright yellow”)

bull1.Material = Enum.Material.Neon

bull1.Anchored = true

bull1.Transparency = 0

bull1.Size = Vector3.new(1,1.2,1)

local mesher = Instance.new(“BlockMesh”)

mesher.Parent = bull1

mesher.Scale = Vector3.new(0.4, 0.4, (mouse.Hit.p - script.Parent.Vehicle.Value.Gun2.Position).magnitude)

local d = game:GetService(“Debris”):AddItem(bull1,0.05)

if mouse.Target.Parent.Parent.Name == “Pirate” or mouse.Target.Parent.Parent.Name == “Fast Pirate” or mouse.Target.Parent.Parent.Name == “Tank Pirate” then

local case = mouse.Target.Parent.Parent:FindFirstChild’Parts’

if case then

if not case:FindFirstChild’Turret’ then return end

local hp = case.Turret:FindFirstChild’Health’

if hp and hp.Value > 0 then

hp.Value = hp.Value - damage

gg.dmg.Text = "HP: " … hp.Value

if hp.Value == 0 then gg:Destroy() end

if gg then gg.Sound:Play() end

end

end

end

wait(0.1)

end

end

end

function onB1U(mouse)

firin = false

end

function onSele(mouse)

mouse.Button1Down:connect(function() onB1D(mouse) end)

mouse.Button1Up:connect(function() onB1U(mouse) end)

mouse.Icon = “http://www.roblox.com/asset/?id=7419350

gg = gui:Clone()

gg.Parent = game.Players.LocalPlayer.PlayerGui

end

function onDeSele()

gg:Destroy()

end

script.Parent.Selected:connect(onSele)

script.Parent.Deselected:connect(onDeSele)

this is the script

3 Likes

Could you put a " ``` " before your code so we can clearly see it? This really hurts my brain

2 Likes

Does it put any errors in the output? Also, at the top of the script editor, click the format button and then click on format document.

"firin = false
damage = 20000
local gui = script.Parent:WaitForChild’gui’
function onB1D(mouse)
firin = true
while firin do
wait()
if mouse.Target.Parent ~= script.Parent.Vehicle.Value and mouse.Target.Parent.Parent ~= script.Parent.Vehicle.Value then
script.Parent.Vehicle.Value.Gun1.Fire:play()
local theTar = mouse.Hit.p
local bull = Instance.new(“Part”)
bull.Parent = game.Workspace
bull.CFrame = CFrame.new((theTar + script.Parent.Vehicle.Value.Gun1.Position)/2,script.Parent.Vehicle.Value.Gun1.Position)
bull.CanCollide = true
bull.BrickColor = BrickColor.new(“Bright yellow”)
bull.Material = Enum.Material.Neon
bull.Anchored = true
bull.Transparency = 0
bull.Size = Vector3.new(1,1.2,1)
local mesher = Instance.new(“BlockMesh”)
mesher.Parent = bull
mesher.Scale = Vector3.new(0.4, 0.4, (mouse.Hit.p - script.Parent.Vehicle.Value.Gun1.Position).magnitude)
local d = game:GetService(“Debris”)
d:AddItem(bull,0.05)
if mouse.Target.Parent.Parent.Name == “Pirate” or mouse.Target.Parent.Parent.Name == “FastPirate” or mouse.Target.Parent.Parent.Name == “TankPirate” or mouse.Target.Parent.Parent.Name == “CloakPirate” or mouse.Target.Parent.Parent.Name == “CarrierPirate” then
local case = mouse.Target.Parent.Parent:FindFirstChild’Parts’
if case then
if not case:FindFirstChild’Turret’ then return end
local hp = case.Turret:FindFirstChild’Health’
if hp and hp.Value > 0 then
hp.Value = hp.Value - damage
gg.dmg.Text = "HP: " … hp.Value
if hp.Value == 0 then gg:Destroy() end
if gg then gg.Sound:Play() end
end
end
end
wait(0.1)
end
if mouse.Target.Parent ~= script.Parent.Vehicle.Value and mouse.Target.Parent.Parent ~= script.Parent.Vehicle.Value then
script.Parent.Vehicle.Value.Gun2.Fire:play()
local theTar = mouse.Hit.p
local bull1 = Instance.new(“Part”)
bull1.Parent = game.Workspace
bull1.CFrame = CFrame.new((theTar + script.Parent.Vehicle.Value.Gun2.Position)/2,script.Parent.Vehicle.Value.Gun2.Position)
bull1.CanCollide = false
bull1.BrickColor = BrickColor.new(“Bright yellow”)
bull1.Material = Enum.Material.Neon
bull1.Anchored = true
bull1.Transparency = 0
bull1.Size = Vector3.new(1,1.2,1)
local mesher = Instance.new(“BlockMesh”)
mesher.Parent = bull1
mesher.Scale = Vector3.new(0.4, 0.4, (mouse.Hit.p - script.Parent.Vehicle.Value.Gun2.Position).magnitude)
local d = game:GetService(“Debris”):AddItem(bull1,0.05)
if mouse.Target.Parent.Parent.Name == “Pirate” or mouse.Target.Parent.Parent.Name == “Fast Pirate” or mouse.Target.Parent.Parent.Name == “Tank Pirate” then
local case = mouse.Target.Parent.Parent:FindFirstChild’Parts’
if case then
if not case:FindFirstChild’Turret’ then return end
local hp = case.Turret:FindFirstChild’Health’
if hp and hp.Value > 0 then
hp.Value = hp.Value - damage
gg.dmg.Text = “HP: " … hp.Value
if hp.Value == 0 then gg:Destroy() end
if gg then gg.Sound:Play() end
end
end
end
wait(0.1)
end
end
end
function onB1U(mouse)
firin = false
end
function onSele(mouse)
mouse.Button1Down:connect(function() onB1D(mouse) end)
mouse.Button1Up:connect(function() onB1U(mouse) end)
mouse.Icon = “http://www.roblox.com/asset/?id=7419350
gg = gui:Clone()
gg.Parent = game.Players.LocalPlayer.PlayerGui
end
function onDeSele()
gg:Destroy()
end
script.Parent.Selected:connect(onSele)
script.Parent.Deselected:connect(onDeSele)”

laser gun.txt (3.4 KB)

next Problem ->i have a question, when i play with 2 players and one kills the other plane, the player sees the plane destroyed but the other player can still fly on with a plane that is not destroyed