I’m currently making an election game that allows the player to simply, vote.
How I’m currently doing this is whenever they press the vote button, it will send a webhook to a Discord channel and I’ll manually count it by using the search features.
Another idea is that I’ll save the number to a Datastore and every time they vote it will +1 of the current number in the datastore then send a webhook of the current number, but I don’t know if it will work accurately or not.
That’s probably the better way to go if you want them to vote in roblox.
Would suggest looking into using Ordered Datastores for that, so you can get a list of the top voted players
Realistically, yes, specifically if there is more than one server. However, you’d probably never hit limitations if you limit an individual to one singular vote (and try to reduce vote spam)
Assuming that roblox datastores don’t go derp and that you have proper error checking, it should not be a problem. (And if anything will be added to the que)
If you’re using a singular player server, and there happens to be multiple instances then UpdateAsync (function of the DataStore class) would probably be the most reasonable option. Because you’ll also need to know when other servers update said values.
local datastore = game:GetService("DataStoreService"):GetDataStore("Person1")
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, voted)
if game.Players:FindFirstChild(player.Name) then
local success, votes = pcall(function()
return datastore:GetAsync("Votes")
end)
local votes = votes or 0
local success, err = pcall(function()
datastore:UpdateAsync("Votes", tonumber(votes)+1)
end)
end
end)
I see, I’d recommend flopping some things around if that’s alright.
local VoteStore = game:GetService("DataStoreService"):GetDataStore("Votes");
-- differentiate based on key
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, votedFor)
local success, err = pcall(function()
datastore:UpdateAsync(votedFor, function(oldValue)
local newValue = oldValue or 0
newValue += 1
return newValue
end)
end
end)
something similar to this however probably wrote better cus exploiters would just be able to fire the remote with said arguments and spam the votes.
Being only one player is in the server, and you only get one vote you could, not the best way to handle it but’d it get the job done as long as no one joins that server after the player leaves
local Con;
Con = game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, votedFor)
if Con then Con:Disconnect() end
What I was thinking is that I add a :Kick() at the end of the remote event and then save them to a datastore which prevents them from joining again, so even if the exploiter did exploit, it would just be the same as voting normally.
Eh I wouldn’t necessarily recommend kicking, you could just use a table and store if the player has voted, but to each their own kicking would work too.
local alreadyVoted = {};
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, votedFor)
if not alreadyVoted[player] then
alreadyVoted[player] = true;
-- rest of code here
end
end)