CCCPaste

FoodsScript(LocalScript)

--- Variables ---

local ToggleVoteEvent = game.ReplicatedStorage.FoodsSystem.ToggleVoteEvent
local AddVoteEvent = game.ReplicatedStorage.FoodsSystem.AddVoteEvent
local Button1 = script.Parent.FoodButton1
local Button2 = script.Parent.FoodButton2

local HasVoted = false

local VoteFrame = script.Parent

local Option1 = game.ReplicatedStorage.FoodsSystem.Food1
local Option2 = game.ReplicatedStorage.FoodsSystem.Food2


--- Toggle Visible ---

ToggleVoteEvent.OnClientEvent:Connect(function(Value)
	
	if Value == true then
		
		VoteFrame.Visible = true
		
	elseif Value == false then
		
		VoteFrame.Visible = false
		
	end
end)

--- Add Vote ---

local function Vote(Button, Option)
	if HasVoted == false then
		HasVoted = true
		
		Button.BackgroundColor3 = Color3.new(0, 255, 255)
		AddVoteEvent:FireServer(Option)
	end
end

Button1.MouseButton1Click:Connect(function()
	Vote(Button1, 1)
end)

Button2.MouseButton1Click:Connect(function()
	Vote(Button2, 1)
end)

--- Update Count ---

Option1.Changed:Connect(function()
	Button1.VoteCount.Text = Option1.Value
end)

Option2.Changed:Connect(function()
	Button2.VoteCount.Text = Option2.Value
end)