I’m creating this art gallery like game and one feature I’m trying to create is a like system. It’s a button that’s on every players art booth, and when a player likes an artist they click the button in support of them.
I’m still learning how to script, I’m kind of noobish. I been watching lots of tutorials and looking at guides for roblox LUA but unfortunately I can’t find the answer to everything I’m trying to do.
What I’m trying to achieve for my like system is that every player can like, and take back their like. It’s meant where you can accumulate likes. But every player can only add and subtract one number.
I have 2 scripts. A server and a local script. In the local script I have it where only the individual player can see their like. The button shows red for if they already clicked the button, and is greyed out if they haven’t clicked the button.
This is the local script
Like = game.Workspace.LikeSystem
Button = Like:WaitForChild("Button")
click = Button:WaitForChild("ClickDetector")
Number = 0
Billboard = Like:WaitForChild("Board")
function onClicked()
if Button.BrickColor == BrickColor.new("Ghost grey") then
Button.BrickColor = BrickColor.new("Bright red")
else if Button.BrickColor == BrickColor.new("Bright red") then
Button.BrickColor = BrickColor.new("Ghost grey")
end
end
end
Button.ClickDetector.MouseClick:connect(onClicked)
For the server script I have it where players can add and subtract their number. The count is visible to everyone.
Here is the script for that
local Billboard = script.Parent.Board
local Button = script.Parent.Button
local Click = Button.ClickDetector
local Number = 0 -- Starting number is always 0
local on = false -- When button is clicked, it will turn on. When clicked again, it will turn off.
Click.MouseClick:Connect(function()
if on == false then -- When button is clicked it will add +1 to the number and turn on.
on = true
Number = Number + 1
Billboard.SurfaceGui.TextLabel.Text = Number -- Displays the number
else
on = false -- when button is clicked again it will subtract 1 number and turn off.
Number = Number - 1
Billboard.SurfaceGui.TextLabel.Text = Number
end
end)
It works like this
Unfortunately, since the server script is applied to everyone, that means it only adds and subtracts by one number, controlled by anyone… I tested it with 2 players, and both players could mess with the button and it only went up by one, and then subtracted when another player pressed the button.
I want to have it where every play can add by one so the likes can accumulate.
Unfortunately I’m struggling to make it work like that.
When I take away the line of code that subtracts the number, if clicked again, then a single player can endlessly click the button and accumulate likes.
How can I make it where it’s limited to only one like per player?