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

How can I make it so a player can click a button once?

Asked by 7 years ago
script.Parent.MouseButton1Click:connect(function()
    script.Parent.Parent.Likes.LikeArtNo.Value = script.Parent.Parent.Likes.LikeArtNo.Value + 1
end)

Here is my code, I want it so a player can increase the value by one but only once, but other players can still do the same once the player clicks it.

EX: PlayerA clicks the button and the Likes go from 0 to 1 then the button's text becomes "Thank you for liking!" on his screen, PlayerA clicks the button again but it does nothing, PlayerB comes and clicks the button (It says it's original text on her screen)and the Likes go from 1 to 2.

By the way, Filtering is Enabled.

1 answer

Log in to vote
0
Answered by 7 years ago

In this scenario I would personally try to keep it as simple as possible (Not sure if this is best, just what I would do). I'm assuming that this is in a local script inside each player's PlayerGui or something similar. I am also assuming that with filtering enabled, you have the required remotes and such so that the value would go up for everyone if you are doing your example with the likes.

I would make what I try to explain as a debounce that never gets reset. What this does is just checks if a value is false, then changes it to true and it never changes back. The player is able to click the button again, but it will not do anything since the if statement is not true.

local db = false

script.Parent.MouseButton1Click:connect(function()
    if db == false then --If they havent done anything yet
        db = true --Make it so they can't click again
        script.Parent.Parent.Likes.LikeArtNo.Value = script.Parent.Parent.Likes.LikeArtNo.Value + 1
    end
end)

If I have helped to answer your question, please remember to accept my answer. If I have made a mistake please message me or comment on my answer on what I have done wrong so that I can either fix my answer or learn from my mistakes. Thanks!

Ad

Answer this question