I am trying to create a voting system, and this script adds the votes to the vote counter above it. However, even though I have variables that keep track of the player's votes, the voting per player does not stop at one. Here is my script. Note my voting system is not complete yet.
local VotingSystem = script.Parent.Parent.Parent
local pad = script.Parent
local Debounce = 1
local PlayerAlreadyVoted = false
local PlayerVotes = 0
print("GTF1")
Votes = 0
print("GTF2")
function OnTouch(Toucher)
print("GTF3")
if Toucher.Parent:FindFirstChild("Humanoid") then
print("GTF4")
Votes = Votes + 1
wait(Debounce)
print("GTF5")
print(Votes)
print("GTF6")
PlayerVotes = 1
if PlayerVotes == 1 then
print("Player already voted!")
script.Parent.Parent.Parent.VoteDisplay1.SurfaceGui.TextLabel.Text = Votes
print("GTF7")
end
print("GTF9")
end
print("GTF10")
end
pad.Touched:Connect(OnTouch)

2 comments
You aren't actually stopping the script from adding more votes on. So every time it runs, it will add 1 because there is no 'if' statement to stop it from doing so
Essentially, all you need to do is check if they already voted and if they did return nil this just breaks the function from happening.