Click Detector Script Help

So I’m trying to make the game have something function when clicked… so what I mean is when the click detector is clicked it’ll find who did it. Check their money. If they have enough money than spend it and continue the functions. Or if they don’t just don’t do anything and basically cancel the script.

How can I do this?

when you start off a click detector code, inside the parenthesis “()” is defined as the player like so:

script.Parent.ClickDetector.MouseClick:Connect(function(playerclicked) -- "playercliked" is the player who clicked it
    -- code here
end)

For checking there money, you can simply look through there leaderstats, or wherever you put the Value like this:

script.Parent.ClickDetector.MouseClick:Connect(function(playerclicked) -- "playercliked" is the player who clicked it
    if playerclicked.leaderstats.Cash.Value >= 100 then -- amount of cash they must have
        playerclicked.leaderstats.Cash.Value = playerclicked.leaderstats.Cash.Value - 100 -- taking away that cash from the player
        -- code here
    end
end)

Another thing to add, it would be better to define the Value and then change it from the new defined string, I was just lazy.

2 Likes

Also, please use Connect with an uppercase “C” because connect with a lowercase “c” is deprecated.

2 Likes

@Hello42bacon it’s still not working for me. Ima post a pic and additional information in a few hours so you can maybe help me out…