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

Why my place tool wont place bricks?

Asked by
ARTEK22 135
8 years ago
Edited 8 years ago

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

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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

0
@DepressionSensei Players.Player1.Backpack.Place.LocalScript:11: bad argument #3 to 'Position' (Vector3 expected, got CFrame) ARTEK22 135 — 8y
0
Sorry, set location to mouse.Hit.P, I accidentally added that to the wrong code block DepressionSensei 315 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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)

Answer this question