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

I need help with my block placer script that's not working right?

Asked by 5 years ago

I dont know why but this script keeps putting down a tower instead of one part. Its suppose to loop and make it so I put one part down at a time but instead it puts down a ton of them stacked on each other and then stops.

Code...

    wait(2)
    local player = game.Players.LocalPlayer
    local mouse = player:GetMouse()
    local blankPart = game.Players.LocalPlayer.PlayerGui.BlockGui.Block.Part
    blankPart.Anchored=true
    blankPart.CanCollide=false
    blankPart.Transparency=0.75

    local mouseDown = false
    local connection

    connection = mouse.Move:Connect(function() 
        if not mouseDown then
         --wait(0.1)
            local part = blankPart:Clone() --never change the original part, only a clone
            part.Parent=workspace
            mouse.TargetFilter=part --ignore the clone while getting mouse position
            local moveConn
            moveConn = mouse.Move:Connect(function()
                local p = mouse.Hit.p
                part.Position = Vector3.new(math.floor(p.X),math.ceil(p.Y),math.floor(p.Z)) --mouse position in whole numbers
            end)
            mouse.Button1Down:Wait() --do not have to connect a click function :)
            moveConn:Disconnect() --stop moving the clone
            part.CanCollide=true
            part.Transparency=0
        end
    end)

    mouse.Button1Down:Connect(function()
        mouseDown = true
        connection:Disconnect() 
    end)        
0
You’re creating a new part every time the mouse moves. User#19524 175 — 5y
1
Oh how do I fix it? protectiverobos -50 — 5y
0
Make an if statement to check if a part is in workspace. User#19524 175 — 5y
1
So if game.workspace.Part then (code)? protectiverobos -50 — 5y
View all comments (4 more)
1
and If game.workspace.Part = nil then (create part)? protectiverobos -50 — 5y
1
But I want if to create a lot of parts, not just one. So I can keep putting more down. protectiverobos -50 — 5y
0
How do I make it so that I can see the part moving when I move the mouse but then I place it , and then I can do it again instead of once? protectiverobos -50 — 5y
0
Try redefining connection on line 12 as mouse button 1click or something instead of move idk why move OBenjOne 190 — 5y

Answer this question