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

Why isn't this shooting the way I'm facing?

Asked by 8 years ago

I'm trying to script build and here is what I have so far:

chr = workspace.supercoolguy53
mouse = game.Players.LocalPlayer:GetMouse()

part = Instance.new("Part",chr)
part.CanCollide = false
part.Anchored = true
part.BrickColor = BrickColor.White()
part.Transparency = .9
part.Size = Vector3.new(7,7,7)
mesh = Instance.new("SpecialMesh",part)
mesh.MeshType = "Sphere"

part.Touched:connect(function(p)
    local h = p.Parent:FindFirstChild("Humanoid")
    if h and h.Parent.Name ~= "supercoolguy53" then
        h.Parent:Destroy()
    end
end)

mouse.KeyDown:connect(function(key)
    if key == 'q' then
        wait()
        clone = part:clone()
        clone.Parent = chr
        clone.Name = 'part1'
        wait()
        for i = 1,500 do
            game:GetService('RunService').RenderStepped:wait()
            clone.CFrame = CFrame.new(clone.Position + (clone.CFrame.lookVector*1))
        end
    end
end)

clone.Touched:connect(function(pA)
    local h = pA.Parent:FindFirstChild("Humanoid")
    if h and h.Parent.Name ~= "supercoolguy53" then
        h.Parent:Destroy()
    end
end)

while game:GetService('RunService').RenderStepped:wait()  do
    part.CFrame = chr.Torso.CFrame
end

It only shoots one way, and if the clone touches someone else they don't get destroyed. But if someone touches the original part they get destroyed:

https://gyazo.com/4da048a5a504ac8308424e23fd0bf245

0
Are you sure mine doesn't work? It works fine for me. You can visit my game and try it, it's the exact same script I answered with. funyun 958 — 8y
1
Nevermind some other script messed it up :/ Senor_Chung 210 — 8y

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago

In my opinion, it's better (and easier) to use body movers (BodyVelocity) when working with projectiles.

player = game.Players.LocalPlayer
mouse = player:GetMouse()
repeat wait() until player.Character
chr = player.Character

template = Instance.new("Part") --We're not going to put it anywhere, it's just a template.
template.CanCollide = false
template.BrickColor = BrickColor.White()
template.Transparency = .9
template.Size = Vector3.new(7,7,7)
template.TopSurface = Enum.SurfaceType.Smooth
template.BottomSurface = Enum.SurfaceType.Smooth

bv = Instance.new("BodyVelocity", template)
bv.maxForce = Vector3.new(math.huge, math.huge, math.huge)

mesh = Instance.new("SpecialMesh",template)
mesh.MeshType = "Sphere"

mouse.KeyDown:connect(function(key)
    if key == 'q' then
        local projectile = template:Clone()
        projectile.Parent = chr
        projectile.Name = 'Projectile'
        projectile.CFrame = chr.Torso.CFrame
        projectile.BodyVelocity.velocity = chr.Torso.CFrame.lookVector * 120

        projectile.Touched:connect(function(pA)
            local h = pA.Parent:FindFirstChild("Humanoid")
            if h and h.Parent.Name ~= player.Name then
                h.Parent:Destroy()
            end
        end)

        wait(4)     
        projectile:Destroy()
    end
end)
Ad

Answer this question