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

Why isn't the Vector3 working to set the Size of a part?

I was making a gun to my game, and i made a code, but then i started getting an error. Then a guy named "Denny9876" told me to use a Vector3 to my code. And then the error was gone! But then, the code wasn't working, only the error was gone.

This is my code:

local pistola = script.Parent
	local hole = game.StarterPack.Pistola.Hole
	 
	-- 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.CFrame = CFrame.new(hole.CFrame.Position)
	       bullet.Transparency = 0.5
	       bullet.CanCollide = false
	        spam = false
	    end
	end)

Pls tell me what is wrong with my code, why isn't the bullet showing up, and how can i fix it?

2 comments

0

You didn't anchor the "bullet", thus it fell through the ground, also, the line "bullet.CFrame = CFrame.new(hole.CFrame.Position)" is unnecessary, you can just do bullet.CFrame =CFrame.new(hole.Position)

0

Thank you

1 answer

✓ Accepted answer

You forgot to parent the Bullet instance to workspace

local pistola = script.Parent
    local hole = game.StarterPack.Pistola.Hole

    -- 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.Parent = game.Workspace--it wont appear just now becuase its not in workspace
           bullet.Size = Vector3.new(range,0.25,0.25)
           bullet.CFrame = CFrame.new(hole.CFrame.Position)
           bullet.Transparency = 0.5
           bullet.CanCollide = false
            spam = false
        end
    end)

1 comment

0

thx

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