Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to one time vote in the round?

I want to create a vote map but when player touching "vote button", yes it working but, it repeat. Through this method player can make 99999999 votes.

a = 0


local function one(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		a = a + 1
		print(a)
	end
end


script.Parent.Touched:Connect(one)

I newbie and I want to know how to one time use.

1 answer

✓ Accepted answer

If it truly is a one-time use, you can simply store the players' names in a table after they touch the part. Then, everytime a touch occurs, simply check to see if their name is in the table before applying the vote.

In a Server Script:

local Voters = {}
local a = 0

script.Parent.Touched:Connect(function(part)
	local Player = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
	if Player then --ensure it is a player touching
		for i,v in pairs(Voters) do --loop through to find a matching name
			if v ~= Player.Name then --if not, add vote
				table.insert(Voters,Player.Name)
				a = a + 1
			end
		end
		if #Voters == 0 then --this is necessary, because the for loop above will not run if there are 0 entries
			table.insert(Voters,Player.Name)
			a = a + 1
		end
	end
end)

1 comment

0

Oh, me need to study many of scripting)

This discussion is preserved as it was. New answers, comments, and votes are closed.