So im trying to make a gun to my game, and it is working fine but when it came to the point to make the bullet appear and set it's position its wont work. Also i want to set its orientation to the mouse position, and also stop it at the closest object.

This is my 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
local coolDown = 1.5
 
-- 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)

So here's a summary of my questions: -Why isn't the position being set; -How can i get the position of the mouse; -How can i set the bullet size to stop when it hits something, like a wall or a player?

Thank you for helping me (if you did helped me XD)

4 comments

0

first of all, is this a local or server script? I can't really tell as you are getting the local player and setting properties of a part

0

also, try using debris service instead of waiting then deleting

0

It would be better to not use Debris.

0

im using a local script