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

Why isn't this shooting?

Asked by 9 years ago

I'm trying to script build and I have this script:

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()
        local clone = part:clone()
        clone.Parent = chr
        clone.Name = 'part1'
        wait()
        for i = 1,500 do
            game:GetService('RunService').RenderStepped:wait()
            chr.part1.CFrame = chr.part1.CFrame.new(chr.Position + (chr.part1.CFrame.lookVector*.1))
        end
    end
end)

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

Everything works except for I can't shoot it. When you press q you're supposed to shoot where ever you're looking, this is my first time with this 'lookVector' thing and I don;t quite understand it. I get this error new is not a valid member

1 answer

Log in to vote
2
Answered by 9 years ago
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()
        local clone = part:clone()
        clone.Parent = chr
        clone.Name = 'part1'
        clone.CFrame = CFrame.new(chr.Head.Position + (chr.Head.CFrame.lookVector*1), mouse.Hit.p)
        wait()
        for i = 1,500 do
            game:GetService('RunService').RenderStepped:wait()
            chr.part1.CFrame = --[[error here]]CFrame.new(chr.Position + (chr.part1.CFrame.lookVector*.1))
        end
    end
end)

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

You forgot the fact that CFrame is a global variable, and that the CFrames of bricks do not contain constructors to create more CFrames. You must use CFrame, not BasePart.CoordinateFrame.

Basically:

local part = Instance.new('Part', workspace)
part.CFrame = part.CFrame.new(0,5,0) --> error: new is not a valid member of part.CFrame
part.CFrame = CFrame.new(0,5,0) --> part gets moved to 0,5,0

I hope I helped, if you have any questions, contact me.

1
It didn't shoot the way I was facing... It was shooting tho. Senor_Chung 210 — 9y
0
Well, that was a problem in your code. It should be fixed now. TerrodactyI 173 — 9y
Ad

Answer this question