So im making a gun to my game, and im using ray's to set the position/orientacion/where to stop the bullet and a guy (at another question) told me to use ray's and he gave me this ray:
local ray = Ray.new(hole.CFrame.Position, (mouse.Hit.Position - hole.CFrame.Position).Unit*range)
But now idk how to use them after creating them, i know that i need to use "findpartinray" but idk where to use it , or how to use it. Anyways here's the 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*range)
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)
Could you tell me where to use it, if i need to add something else and also a fix pls :D Thx! (also pls send an answer, dont add a commentary pls)

3 comments
This is the second time i post this question because the last time nobody answered me :P
you shouldn't using instance.new in a local script if you want other players to see a projectile
I'm not sure how fast this bullet is going to be but personally I would use a Ray for something like an instantaneous speed projectile (i.e. a laser) and Touched for something like a bullet/rocket