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

I'm trying to make a turret that shoots bullets. Is anything wrong with this code?

Asked by 3 years ago

Hello. So basically, I wanted to make a turret. I made a script, and there seem to be errors. What is the problem? Im... not that experienced with coding. Here is the code:

part = script.Parent


while wait(0.01) do
for i,v in pairs(workspace:GetDescendants()) do
    if v.Name == "Humanoid" then
        humanoid = v
end 
end
    if humanoid.Parent == "Finty_james" then
        return
    end
    else 
    local torso = humanoid.Parent.Torso
    local bullet = game.ReplicatedStorage.Bullet
    local newBullet = bullet:Clone()
    part.Anchored = false
    part.Orientation = torso.Orientation
    part.Anchored = true
    newBullet.Parent = workspace
    newBullet.Position = part.Position
    newBullet.AssemblyLinearVelocity = Vector3.new(torso.Position)
    part.Anchored = false
end

This is my code. Since all the parts couldn't stay in place (Due to the Gravity Property, which I won't be changing,) this is the reason why I used the anchored property 3 times. Also, the Velocity Statement is kinda like a Body Force, but it's a property and can be altered by the Gravity Property of the Workspace Object In Roblox studio.

0
are there error messages? Gmorcad12345 434 — 3y
0
Yes Finty_james 269 — 3y
0
Also why I got the humanoid, is because I wanted to make it damage a NPC, but it wouldnt damage me. But I wasnt focusing on that. Finty_james 269 — 3y
0
Also why I got the humanoid, is because I wanted to make it damage a NPC, but it wouldnt damage me. But I wasnt focusing on that. Finty_james 269 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
if humanoid.Parent.Name == "Finty_james" then -- you forgot the .Name
        return
    --why is there an 'end' here?
    else 
    local torso = humanoid.Parent.Torso
    local bullet = game.ReplicatedStorage.Bullet
    local newBullet = bullet:Clone()
    part.Anchored = false
    part.Orientation = torso.Orientation
    part.Anchored = true
    newBullet.Parent = workspace
    newBullet.Position = part.Position
    newBullet.AssemblyLinearVelocity = Vector3.new(torso.Position)
    part.Anchored = false
end
Ad

Answer this question