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

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

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

4 comments

0

If there's something I need to add or remove then yah... just tell me

0

Could you tell us the error atleast....

0

IDK

0

It doesn't give me an error actually, it just always goes backward, but it goes backward in position not CFrame

1 answer

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)

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