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

On click function wont work as intended, help?

Asked by
plmpo 0
5 years ago
I am a beginner scripter. I have been working on this code for hours and have multiple variants of it of which none after I started editing after I got it to turn on and off.

~~This works

local lfe = true

function collect()
    local lfe = true
    script.Parent.ge.Reflectance = .5
end

function dead()
    local lfe = false
    script.Parent.ge.Reflectance = 0
end

function onClicked()
    if lfe == true then wait() dead() else collect()
    end


end

script.Parent.ge.ClickDetector.MouseClick:Connect(onClicked)

collect()

~~ I am trying to edit it to where Left click and hold keeps it on true and doesn't turn false until I let go.

~~ My attempts ( I apologize for the length I gave it an honest attempt.)

First Attempt:

local lfe = true

function collect()
    local lfe = true
    script.Parent.ge.Reflectance = .5
end

function dead()
    local lfe = false
    script.Parent.ge.Reflectance = 0
end

function onClicked()
    wait (1)
    if lfe == true then dead() else collect() end

end

script.Parent.ge.ClickDetector.Button1Down:Connect(onClicked)

collect()

~~ I am trying to edit it to where Left click and hold keeps it on true and doesn't turn false until I let go.

~~ My attempts ( I apologize for the length I gave it an honest attempt.)

Second attempt:

local Player = game.Players.LocalPlayer
local Mouse = Player.GetMouse()
local lfe = true


if Mouse.Button1Down:Connect(function(collect)

end)
then Mouse.Button1Up:Connect(function(dead)
    end)
end



function collect()
    local lfe = true
    script.Parent.ge.Reflectance = .5
end

function dead()
    local lfe = false
    script.Parent.ge.Reflectance = 0
end

function onClicked()
    if lfe == true then wait() dead() else collect()
    end


end

script.Parent.ge.ClickDetector.MouseClick:Connect(onClicked)

collect()

Third attempt:

local Player = game.Players.LocalPlayer
local Mouse = Player.GetMouse()
local lfe = true

function collect()
    Mouse.Button1Down = true
    local lfe = true
    script.Parent.ge.Reflectance = .5
end

function dead()
    Mouse.Button1Down = false
    local lfe = false
    script.Parent.ge.Reflectance = 0
end

function onClicked()
    wait (1)
    if lfe == true then dead() else collect() end

end

script.Parent.ge.ClickDetector.MouseClick:Connect(onClicked)

collect()

Fourth Attempt:

local Player = game.Players.LocalPlayer
local Mouse = Player.GetMouse()
local Re = true


function onClick()
    Mouse.Button1Down = true
    if Mouse.Button1Down then pick()

    end
end




function pick()
    local Re = true
    while true do
        script.Parent.ge.Transparency = .1
        wait (onClickOff)
        script.Parent.ge.Transparency = 0
    local Re = false

    end
end

function onClickOff()
    Mouse.Button1Down = false
end

script.Parent.ge.ClickDetector.MouseClick:Connect(onClick)

~~

That's not all but I don't have the rest saved, These are the 5 scripts I have kept in-game for now however. Some advice would be much appreciated! Thank you.
I've tried looking for tutorials and the RobloxDev Scripting guide, but so far nothing I tried has worked.
0
mouse.Button1Down is an event, not a property. And LocalPlayer and the mouse are inaccessible by the server. User#19524 175 — 5y
0
I just realised clickdetector doesnt have a button1down event, that is interesting, it could be rather useful such as in a case like this aazkao 787 — 5y
0
Thank you incapaz, I didnt know, ill try to work around that fact. plmpo 0 — 5y

Answer this question