Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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?

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) theking48989987 2147 — 6y
0
Thank you mewant_taco 17 — 6y

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
thx mewant_taco 17 — 6y
Ad

Answer this question