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

When making a gun, why does CFrame not work? [local script] [closed]

Asked by 3 years ago

So I can't make this work, and I keep getting an error. Does "CFrame.new()" even work in a local script?

code [local script]:

local Tool = script.Parent.Parent
local debounce = false
local fireRate = 0.2
local distance = 30

Tool.Equipped:Connect(function(Mouse)

    if not debounce then

        debounce = true

        Mouse.Button1Down:Connect(function()

            local brick = Instance.new('Part', workspace)
            brick.Size = Vector3.new(0.75, 0.75, 0.75)
            brick.CFrame = script.Parent.CFrame

            repeat

                brick.Anchored = true
                brick.CFrame = brick.CFrame + Vector3.new(0, 0, 3)
                wait(0.05)

            until((brick.Position - script.Parent.Position).magnitude >= distance)

            brick.Anchored = false

        end)

        wait(fireRate)

        debounce = false

    end

end)

If this also happens to you let me know and if you figured out how to fix it also let me know. Thanks, bye! :P

0
If there's something I need to add or remove then yah... just tell me huntergamind 2 — 3y
0
Could you tell us the error atleast.... birds3345 177 — 3y
0
IDK huntergamind 2 — 3y
0
It doesn't give me an error actually, it just always goes backward, but it goes backward in position not CFrame huntergamind 2 — 3y

Closed as Non-Descriptive by Lakodex and JesseSong

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
3 years ago
Edited 3 years ago

Here is your fixed script.

local Tool = script.Parent.Parent
local debounce = false
local fireRate = 0.2
local distance = 30

Tool.Equipped:Connect(function(Mouse)

    if not debounce then

        debounce = true

        Mouse.Button1Down:Connect(function()

            local brick = Instance.new('Part', workspace)
            brick.Size = Vector3.new(0.75, 0.75, 0.75)
            brick.CFrame = script.Parent.CFrame

            repeat

                brick.Anchored = true
                brick.CFrame = brick.CFrame + CFrame.new(0, 0, -3)
                wait(0.05)

            until((brick.Position - script.Parent.Position).magnitude >= distance)

            brick.Anchored = false

        end)

        wait(fireRate)

        debounce = false

    end

end)
Ad