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

Why my place tool wont place bricks?

So i am making a tool where you can place bricks, but they wont place and won't even show me an error. Here is the script.

local mouse = game.Players.LocalPlayer:GetMouse()
	local Tool = script.Parent
	local location = mouse.Hit

 
Tool.Equipped:connect(function(Mouse)
	Mouse.Button1Down:connect(function()
			local part = Instance.new('Part')
	part.Parent = workspace
	part.Anchored = true
	part.CFrame = location
	end)
		Mouse.Button1Up:connect(function()
		wait(30)
		game.Workspace.Part:remove()
	end)
end)

2 answers

✓ Accepted answer

Why did you define a mouse if you weren't going to use it in the first place? lol First issue is that the Mouse argument is a newly created Mouse object that isn't the player's mouse. It exists, so it won't error, but the functions won't run. Your second issue is that Mouse.Hit is a CFrame value, but it won't return the CFrame's Vector value.

Here's your code:

local mouse = game.Players.LocalPlayer:GetMouse()
local Tool = script.Parent
local location = mouse.Hit


Tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()
            local part = Instance.new('Part')
    part.Parent = workspace
    part.Anchored = true
    part.CFrame = location
    end)
        Mouse.Button1Up:connect(function()
        wait(30)
        game.Workspace.Part:remove()
    end)
end)

Here's your code, but with some fixes:

local mouse = game.Players.LocalPlayer:GetMouse()
    local Tool = script.Parent


Tool.Equipped:connect(function()
    mouse.Button1Down:connect(function()
    local location = mouse.Hit.p
    local part = Instance.new('Part')
    part.Parent = workspace
    part.Anchored = true
    part.Position = location
    end)
        mouse.Button1Up:connect(function()
        wait(30)
        game.Workspace.Part:remove()
    end)
end)

If this helped you, don't forget to accept the answer :D

2 comments

0

@DepressionSensei Players.Player1.Backpack.Place.LocalScript:11: bad argument #3 to 'Position' (Vector3 expected, got CFrame)

0

Sorry, set location to mouse.Hit.P, I accidentally added that to the wrong code block

I get that you want the part to remove after 30 seconds here is better way to do this:

Your way:

 local mouse = game.Players.LocalPlayer:GetMouse()
    local Tool = script.Parent


Tool.Equipped:connect(function()
    mouse.Button1Down:connect(function()
    local location = mouse.Hit.p
    local part = Instance.new('Part')
    part.Parent = workspace
    part.Anchored = true
    part.Position = location
    end)
        mouse.Button1Up:connect(function()
        wait(30)
        game.Workspace.Part:remove()
    end)
end)

My way:

local mouse = game.Players.LocalPlayer:GetMouse()
    local Tool = script.Parent


Tool.Equipped:connect(function()
    mouse.Button1Down:connect(function()
    local location = mouse.Hit.p
    local part = Instance.new('Part')
    part.Parent = workspace
    part.Anchored = true
    part.Position = location
game:GetService('Debris'):AddItem(part,30)
end)
end)

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