#How to add wait command

1 messages · Page 1 of 1 (latest)

formal ember
#

I just bought a scripted gun game, but the voting starts as soon as we load and as soon as we go back to lobby it starts again, i want to add a time after which the voting appeares

#

The script:

local module = {}

local status= game.ReplicatedStorage.Values.Status

local mapVotes = {}

function getMap()

local randomMap = game.ReplicatedStorage.Maps:GetChildren()[math.random(1, #game.ReplicatedStorage.Maps:GetChildren())]
for i, map in pairs(mapVotes) do
    if map.name == randomMap.Name then
        return getMap()
    end
end
return randomMap.Name

end

function module.MapVoting(dur)
mapVotes = {}
for i = 1,3 do
table.insert(mapVotes,{order =i, name = getMap(); players = {}})
end
game.ReplicatedStorage.Events.UpadteVoting:FireAllClients(mapVotes)

game.ReplicatedStorage.Values.VotingProggress.Value = true

local placeVoteConnection = game.ReplicatedStorage.Events.PlaceVote.OnServerEvent:Connect(function(player, voteNumber)
    for i,map in pairs(mapVotes) do
        for x, plr in pairs(map.players) do
            if plr == player.UserId then
                table.remove(map.players, x)
                break
            end
        end
    end
    for i, map in pairs(mapVotes) do
        if map.order == voteNumber then
            table.insert(map.players, player.UserId)
        end
    end
    game.ReplicatedStorage.Events.UpadteVoting:FireAllClients(mapVotes)
end)
for i = dur,0,-1 do
    status.Value = "You have "..i..((i==1 and " second")or" seconds").." to vote!"
    task.wait(1)
end

placeVoteConnection:Disconnect()

game.ReplicatedStorage.Values.VotingProggress.Value = false

table.sort(mapVotes, function(a,b) return #a.players > #b.players end)

local winner

if #mapVotes[1].players == #mapVotes[2].players and #mapVotes[2].players == #mapVotes[3].players then
    winner = mapVotes[math.random(1,3)]
elseif #mapVotes[1].players == #mapVotes[2].players then
    winner = mapVotes[math.random(1,2)]
else
    winner = mapVotes[1]
end
status.Value = winner.name.." was chosen!"
wait(2)
status.Value = " "
return game.ReplicatedStorage.Maps:FindFirstChild(winner.name)

end

return module

random scroll
formal ember
#

@random scroll that didnt work bro

random scroll
#

Show the code you changed

formal ember
#

local status= game.ReplicatedStorage.Values.Status

local mapVotes = {}

function getMap()
    
    local randomMap = game.ReplicatedStorage.Maps:GetChildren()[math.random(1, #game.ReplicatedStorage.Maps:GetChildren())]
    for i, map in pairs(mapVotes) do
        if map.name == randomMap.Name then
            return getMap()
        end
    end
    return randomMap.Name
end

task.wait(5)

function module.MapVoting(dur)
    mapVotes = {}
    for i = 1,3 do
        table.insert(mapVotes,{order =i, name = getMap(); players = {}})
    end
    game.ReplicatedStorage.Events.UpadteVoting:FireAllClients(mapVotes)
    
    game.ReplicatedStorage.Values.VotingProggress.Value = true
    
    local placeVoteConnection = game.ReplicatedStorage.Events.PlaceVote.OnServerEvent:Connect(function(player, voteNumber)
        for i,map in pairs(mapVotes) do
            for x, plr in pairs(map.players) do
                if plr == player.UserId then
                    table.remove(map.players, x)
                    break
                end
            end
        end
        for i, map in pairs(mapVotes) do
            if map.order == voteNumber then
                table.insert(map.players, player.UserId)
            end
        end
        game.ReplicatedStorage.Events.UpadteVoting:FireAllClients(mapVotes)
    end)
    for i = dur,0,-1 do
        status.Value = "You have "..i..((i==1 and " second")or" seconds").." to vote!"
        task.wait(1)
    end
    
    placeVoteConnection:Disconnect()
    
    game.ReplicatedStorage.Values.VotingProggress.Value = false
    
    table.sort(mapVotes, function(a,b) return #a.players > #b.players end)
    
    local winner
    
    if #mapVotes[1].players == #mapVotes[2].players and #mapVotes[2].players == #mapVotes[3].players then
        winner = mapVotes[math.random(1,3)]
    elseif #mapVotes[1].players == #mapVotes[2].players then
        winner = mapVotes[math.random(1,2)]
    else
        winner = mapVotes[1]
    end
    status.Value = winner.name.." was chosen!"
    wait(2)
    status.Value = " "
    return game.ReplicatedStorage.Maps:FindFirstChild(winner.name)
    
end

return module```
#

wait

random scroll
#

no thats not what i meant

#

thats just delaying your module loading by 5 seconds

formal ember
#

oh

random scroll
#

Whever in the code you actually call the module.MapVoting() function, add a delay before it

#

so do CTRL+F and search for .MapVoting( and see where its being called

formal ember
#

task.wait(5)

function module.MapVoting(dur)
mapVotes = {}
for i = 1,3 do
table.insert(mapVotes,{order =i, name = getMap(); players = {}})
end

quaint grottoBOT
#

studio** You are now Level 1! **studio

formal ember
#

this?

random scroll
#

no thats still the function deffinition

#

Do you know how to code at all?

#

(not meant to be rude sorry if that was rude)

formal ember
#

fr i dont

#

no problem i dont mind stuff

random scroll
formal ember
#

thanks alot 🫡