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

I need help with mousebutton1Down please?

Asked by
Damo999 182
9 years ago

I made this script when I press my mouse button it changes the nozzle color to red and it should spray red paint and when I let go of my mouse button it should stop but for some reason when I click the the button the nozzle turns red but nothing is spraying , but when I let go of my mouse button that is when the paint starts to spray can someone help me thank you :)

here's the code

nozzle = script.Parent
mouse = game.Players.Player1:GetMouse()
spraying = false

function sprayingg()
    if spraying == false then
        spraying = true
        if spraying then
            print("Spraying")
            while spraying do
                nozzle.BrickColor = BrickColor.Red()
                wait()
            end
        end
    end
end

function sprayPaint()
    if spraying == false then
        spraying = true
        while spraying do
            paint = Instance.new("Part",Workspace)
            paint.BrickColor = BrickColor.new(21)
            paint.FormFactor = Enum.FormFactor.Custom
            paint.Size = Vector3.new(1, 0.2, 0.6)
            paint.Position = mouse.Hit.p
            wait()
            end
        end
end

mouse.Button1Down:connect(function()
    sprayingg()
    sprayPaint()
end)

mouse.Button1Up:connect(function()
    if spraying == true then
        spraying = false
        if not spraying then
            print("Not spraying")
            nozzle.BrickColor = BrickColor.new("Institutional white")

        end
    end
end)

1 answer

Log in to vote
-2
Answered by 9 years ago

wait is the sprayingg supposed to be like that?? and i think you need to get rid of"Player1"

Ad

Answer this question