Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to one time vote in the round?

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
Oh, me need to study many of scripting) AgentViteC 58 — 3y
Ad

Answer this question