Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't the position being set?

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
-- 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: 1: Why isn't the position being set; 2: How can i get the position of the mouse; 3: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) Also im using a local script, if you need to know...

6 comments

0

Also this is the second time i post this, cuz the first time i waited for 5 days and got no answer so, yeah. XD

0

You know you can ray cast right

0

local ray = Ray.new(hole.CFrame.Position, (mouse.Hit.Position - hole.CFrame.Position).Unit*number)

0

still doesn't work ;-;

0

duh, bc thats only a part of raycasting, you need to use :FindPartOnRay()

0

oh ok, could you send me a fix? im bad at scripting sry

1 answer

The position is represented by CFrame.

Bullet.CFrame =  hole.CFrame

1 comment

0

it didn't worked ;-;

This discussion is preserved as it was. New answers, comments, and votes are closed.