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

Why is MouseButton1Down malfunctioning?

Asked by 6 years ago

I have a localscript that is in a TextButton. When i click anywhere , the effect is the same to clicking the button. Why does this happen? How can i fix it?script:

local ready = false
function onMouseButton1Down()
    ready = true
end
local sp = script.Parent
sp.MouseButton1Down:Connect(onMouseButton1Down())
repeat wait(0.1) until ready == true
if ready == true then
    local click = false
    local clone = game:GetService("ReplicatedStorage").Plane:Clone()
    local mouse = game.Players.LocalPlayer:GetMouse()
    local firstclick = false
    clone.Parent = workspace
    function invisible(model,scale)
        local c = model:GetChildren()
        for i= 1, #c do 
            if c[i].className ~= "Model" then 
                c[i].Transparency = scale
            else
                invisible(c[i],scale)
            end 
        end 
    end
    function anchor(model,bool)
        local c = model:GetChildren()
        for i= 1, #c do 
            if c[i].className == "Model" or c[i].className == "Folder" then 
                anchor(c[i],bool)
            else
                c[i].Anchored = bool
            end 
        end 
    end
    function collide(model,bool)
        local c = model:GetChildren()
        for i= 1, #c do 
            if c[i].className == "Model" or c[i].className == "Folder" then 
                collide(c[i],bool)
            else
                c[i].CanCollide = bool
            end 
        end 
    end
    anchor(clone,true)
    collide(clone,false)
    invisible(clone,0.6)
    mouse.Button1Down:connect(function()
        if firstclick == false then
            click = true
            firstclick = true
            invisible(clone,0.6)
        end
        while click == true do
            clone:MoveTo(mouse.Hit.Position)
            anchor(clone,true)
            wait(0.01)
        end
    end)
    mouse.Button1Up:connect(function()
        if click ~= false then
            click = false
            wait(0.02)
            collide(clone,true)
            anchor(clone,false)
            invisible(clone,0)
            clone.VehicleSeat.Main.Disabled = false --only for this item --
        end
    end)
end

1 answer

Log in to vote
0
Answered by 6 years ago

On line 6 you're not supposed to have the parenthesis included for the argument of Connect().

Remove the parenthesis () after onMouseButton1Down in line 6.

Ad

Answer this question