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

Why isn't the position being set?

Asked by 6 years ago
Edited 6 years ago

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...

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 mewant_taco 17 — 6y
0
You know you can ray cast right User#19524 175 — 6y
0
local ray = Ray.new(hole.CFrame.Position, (mouse.Hit.Position - hole.CFrame.Position).Unit*number) User#19524 175 — 6y
0
still doesn't work ;-; mewant_taco 17 — 6y
View all comments (2 more)
0
duh, bc thats only a part of raycasting, you need to use :FindPartOnRay() User#23365 30 — 6y
0
oh ok, could you send me a fix? im bad at scripting sry mewant_taco 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The position is represented by CFrame.

Bullet.CFrame =  hole.CFrame
0
it didn't worked ;-; mewant_taco 17 — 6y
Ad

Answer this question