I made this vote code and tested it with some people. There are 4 bars on the baseplate that show how much votes what color has, like a graph and it also updates across all servers. The thing is the vote didn’t count for one guy and I have no idea what the problem is. I am not experienced enough with roblox data stores and may made some mistakes. Please help me out to fix this
local dss = game:GetService("DataStoreService")
local votes = dss:GetDataStore('Votes')
local didvote = dss:GetDataStore('DidVote')
local tweenService = game:GetService('TweenService')
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut)
local meters = {workspace.Red.Meter,workspace.Yellow.Meter,workspace.Green.Meter,workspace.Blue.Meter}
local texts = {workspace.Red.Brick.SurfaceGui.TextLabel,workspace.Yellow.Brick.SurfaceGui.TextLabel,workspace.Green.Brick.SurfaceGui.TextLabel,workspace.Blue.Brick.SurfaceGui.TextLabel}
local numtotext = {'Red','Yellow','Green','Blue'}
local buttons = {workspace.Red.Button,workspace.Yellow.Button,workspace.Green.Button,workspace.Blue.Button}
local buttonInfoIn = TweenInfo.new(.2,Enum.EasingStyle.Sine,Enum.EasingDirection.In)
local buttonInfoOut = TweenInfo.new(.2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)
local metermax = 18
local rs = game:GetService('ReplicatedStorage')
local sendmsg = rs.sendmsg
for i = 1, 4 do
local debounce = false
buttons[i].ClickDetector.MouseClick:Connect(function(player)
if debounce == true then
return
end
local success, did = pcall(function()
return didvote:GetAsync('Player_'..player.UserId)
end)
if success then
if did == true then
sendmsg:FireClient(player,'You have already voted!')
return
end
debounce = true
didvote:SetAsync('Player_'..player.UserId,true)
votes:IncrementAsync(numtotext[i],1)
buttons[i].Sound:Play()
tweenService:Create(buttons[i],buttonInfoIn,{Size=Vector3.new(1,.2,1)}):Play()
wait(.2)
tweenService:Create(buttons[i],buttonInfoOut,{Size=Vector3.new(1,1,1)}):Play()
wait(.3)
debounce = false
else
sendmsg:FireClient(player,'Unable to access data')
end
end)
end
function update()
local success,vote_table = pcall(function()
local r,y,g,b = votes:GetAsync('Red'),votes:GetAsync('Yellow'),votes:GetAsync('Green'),votes:GetAsync('Blue')
return {r,y,g,b}
end)
if success then
for i = 1, 4 do
vote_table[i] = vote_table[i] or 0
end
local max = math.max(vote_table[1],vote_table[2],vote_table[3],vote_table[4])
for i = 1, 4 do
texts[i].Text = vote_table[i]
vote_table[i] /= max
tweenService:Create(meters[i],tweenInfo,{Size=Vector3.new(2,metermax*vote_table[i],0)}):Play()
end
end
end
update()
while wait(2) do
update()
end