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

This shooting script does not work at all, does not shoot?

This following script is supposed to instance a new part, and make it shoot towards the player but it dosent do that! Thanks for the help

local function Shoot()

    local bullet = Instance.new("Part", workspace.Bullets.EnemyBullets)
    bullet.Size = Vector3.new(0.3,0.3,0.3)
    bullet.Material = "Neon"

    bullet.CFrame = Enemy.Torso.CFrame * CFrame.new(0,0,-4)
    bullet.CanCollide = false

    local velocity = Instance.new("BodyVelocity", bullet)
    velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bullet.CFrame = CFrame.new(bullet.Position, game.Players.LocalPlayer.Character.HumanoidRootPart.Position)
    velocity.Velocity = bullet.CFrame.lookVector * 500 + Vector3.new(math.random(-25,25),math.random(-25,25),0)

end


while wait(2) do

    Shoot()

end

2 comments

0

Is the script a LocalScript?

0

yes it is. I've tried it in a server script and didn't change anything

1 answer

✓ Accepted answer

You said in the comments that this was in a LocalScript. LocalScripts are meant for things that only the client can see, so no other clients in the server will be able to see the bullet. However, it's not as easy as just switching it to a server script, as you referenced game.Players.LocalPlayer, which only LocalScripts can use.

Assuming that this script is in a Tool, then we can easily access the Character, as equipped tools are in the character model itself. If the script is under the Tool directly, then you can reference script.Parent.Parent to get the character. If it's in the handle, add an extra .Parent to compensate for it. (The new line below shows it as if it is under the Tool directly)

So, the script should be changed to a server script, and the new line 12 should be:

bullet.CFrame = CFrame.new(bullet.Position, script.Parent.Parent.HumanoidRootPart.Position)

Hope this helped.

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