#How to add wait command
1 messages · Page 1 of 1 (latest)
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
Most likely you can add some task.wait(duration: number) statements before the MapVoting function is called
Also please format your code when sending it in discord:
thanks alot, i didnt know about format
@random scroll that didnt work bro
Show the code you changed
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
oh
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
task.wait(5)
function module.MapVoting(dur)
mapVotes = {}
for i = 1,3 do
table.insert(mapVotes,{order =i, name = getMap(); players = {}})
end
** You are now Level 1! **
this?
no thats still the function deffinition
Do you know how to code at all?
(not meant to be rude sorry if that was rude)
I'd recommend learning, here is roblox's script fundamentals course
https://create.roblox.com/docs/tutorials/fundamentals/coding-1/coding-fundamentals
It should teach you the basics of writing code.
Once you understand how to script you can read the documentation to get a more detailed understanding
- Roblox documentation: https://create.roblox.com/docs
- Luau documentation: https://create.roblox.com/docs/scripting
thanks alot 🫡