I made a gun, that is attached to a car. But if i click the button 1 down on the mouse, it doesnt do anything. The script is in the vehicle seat, and is a localscript.
script:
local isincar = false
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local h = script.Parent.Parent.Parent.Body.lala
mouse.Button1Down:Connect(function()
local ray = Ray.new(h.CFrame.p, (mouse.Hit.p - h.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local b = Instance.new("Part")
b.BrickColor = BrickColor.new("Bright red")
b.FormFactor = "Custom"
b.Material = "Neon"
b.Transparency = 0.25
b.Anchored = true
b.Locked = true
b.CanCollide = false
local distance = (h.CFrame.p - position).magnitude
b.Size = Vector3.new(0.3, 0.3, distance)
b.CFrame = CFrame.new(h.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(b, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(30)
end
end
end)
i used roblox's tutorial as a test xdd

1 comment
It doesn't work because LocalScripts don't run in Workspace, and FormFactor is deprecated.