Im trying to make a gun so i made this script (you dont need to read it lol):
local pistola = script.Parent
local hole = game.StarterPack.Pistola.Hole
local mouse = game.Players.LocalPlayer:GetMouse()
-- Lista de Valores --
local ammo = 12
local maxAmmo = 64
local damage = 20
local headshotDamage = 50
local range = 100
-- impedir spamming --
local spam = false
-- Disparo --
pistola.Activated:Connect(function()
if spam == false then
spam = true
pistola.Handle.Disparo:Play()
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(range,0.25,0.25)
bullet.Position = hole.Position
bullet.Transparency = 0.5
bullet.CanCollide = false
bullet.Anchored = true
bullet.Parent = game.Workspace
wait(0.5)
bullet:Destroy()
spam = false
end
end)
But then i couldn't set the position so i asked another question at this website and i found out i have to use a ray so i ended up with this new script:
local pistola = script.Parent
local hole = game.StarterPack.Pistola.Hole
local mouse = game.Players.LocalPlayer:GetMouse()
-- Lista de Valores --
local ammo = 12
local maxAmmo = 64
local damage = 20
local headshotDamage = 50
local range = 100
-- impedir spamming --
local spam = false
-- Disparo --
pistola.Activated:Connect(function()
if spam == false then
spam = true
pistola.Handle.Disparo:Play()
local bullet = Instance.new("Part")
local ray = Ray.new(hole.CFrame.Position, (mouse.Hit.Position - hole.CFrame.Position).Unit*number)
bullet.Size = Vector3.new(range,0.25,0.25)
bullet.Position = hole.Position
bullet.Transparency = 0.5
bullet.CanCollide = false
bullet.Anchored = true
bullet.Parent = game.Workspace
wait(0.5)
bullet:Destroy()
spam = false
end
end)
But it didn't work either so i went to watch some tutorials about making guns on roblox and i found out that they used raycasting too, so im trying to find out how to use my ray. Pls explain me how to use the ray and also a fix if you could. :D

4 comments
https://www.robloxdev.com/articles/Making-a-ray-casting-laser-gun-in-Roblox use this tutorial, but theres some decaperated stuff in there
like FormFactor and the parent parameter of Instance.new() and also :connect so use :Connect
Ok thx
But i still dont understand how to do it :/