Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local alreadyVoted = {}
- local caveVotes = 0
- local desertVotes = 0
- local landVotes = 0
- local reset = false
- local countdownLabels = {}
- local voteLabels = {}
- local promptList = {}
- local entityPositions = {}
- local timersEnded = false
- local timer = 30 -- the timer number like how long is the timer
- local timerEndCount = 0
- local players = PlayerService.getPlayers()
- local playerCount = #players
- local maxVotes = playerCount > 1 and math.ceil(playerCount / 2) or 1
- local voteCount = 0
- local function endTimers()
- timersEnded = true
- for _, label in pairs(countdownLabels) do
- if label then
- label:destroy()
- end
- end
- end
- local function determineWinner(winner)
- endTimers()
- reset = true
- local winningPosition
- if winner == "cave" then
- winningPosition = Vector3.new(207, 63, 243)
- elseif winner == "desert" then
- winningPosition = Vector3.new(222, 63, 243)
- elseif winner == "land" then
- winningPosition = Vector3.new(237, 63, 243)
- end
- for _, player in ipairs(PlayerService.getPlayers()) do
- local entity = player:getEntity()
- if entity then
- entity:setPosition(winningPosition)
- end
- end
- for _, position in ipairs(entityPositions) do
- local nearbyEntities = EntityService.getNearbyEntities(position, 4)
- if nearbyEntities then
- for _, entity in ipairs(nearbyEntities) do
- local maxHealth = entity:getMaxHealth()
- if maxHealth and maxHealth > 0 then
- CombatService.damage(entity, maxHealth * 2)
- end
- end
- end
- end
- for option, label in pairs(countdownLabels) do
- if label then
- label:destroy()
- end
- end
- for option, label in pairs(voteLabels) do
- if label then
- label:destroy()
- end
- end
- for _, player in ipairs(PlayerService.getPlayers()) do
- local entity = player:getEntity()
- if entity then
- for _, option in ipairs({"cave", "desert", "land"}) do
- local imageEntity = EntityService.spawnImageEntity("rbxassetid://image_id_here", entity:getPosition() + Vector3.new(0, 18, 0))
- if imageEntity then
- imageEntity:setCustomName(option)
- imageEntity:setMaxHealth(-99999999999999999999999999999)
- end
- end
- end
- end
- for option, prompt in pairs(promptList) do
- if prompt then
- prompt:destroy()
- end
- end
- caveVotes = 0
- desertVotes = 0
- landVotes = 0
- voteCount = 0
- timersEnded = true
- alreadyVoted = {}
- entityPositions = {}
- end
- local function checkForWinner()
- local winner
- local highestVotes = math.max(caveVotes, desertVotes, landVotes)
- local tiedOptions = {}
- if caveVotes == highestVotes then
- table.insert(tiedOptions, "cave")
- end
- if desertVotes == highestVotes then
- table.insert(tiedOptions, "desert")
- end
- if landVotes == highestVotes then
- table.insert(tiedOptions, "land")
- end
- if #tiedOptions > 1 then
- winner = tiedOptions[math.random(#tiedOptions)]
- else
- winner = tiedOptions[1]
- end
- determineWinner(winner)
- end
- local function createVoteUI(votePosition, option, mapId)
- local entity = EntityService.spawnImageEntity("rbxassetid://" .. mapId, votePosition + Vector3.new(0, 18, 0))
- if not entity then return end
- entity:setCustomName(option)
- entity:setMaxHealth(999999)
- local b = entity:getModel()
- b:setScale(3)
- b:setCollidable(false)
- b:setAnchored(true)
- table.insert(entityPositions, votePosition + Vector3.new(0, 18, 0))
- Events.EntityDamage(function(event)
- if event.entity == entity then
- event.knockback.horizontal = 0
- event.knockback.vertical = 0
- end
- end)
- local voteTextPosition = votePosition + Vector3.new(0, 8.5, 0)
- voteLabels[option] = UIService.createTextLabel("0/" .. tostring(maxVotes), voteTextPosition)
- voteLabels[option]:setBackgroundColor(Color3.fromRGB(0, 0, 0))
- voteLabels[option]:setBackgroundTransparency(0.9)
- voteLabels[option]:setTextColor(Color3.fromRGB(255, 255, 255))
- voteLabels[option]:setSize(UDim2.fromScale(10, 2))
- voteLabels[option]:setFont(Font.Arcade)
- local countdownPosition = votePosition + Vector3.new(0, 10, 0)
- countdownLabels[option] = UIService.createTextLabel("⏱️ " .. timer, countdownPosition)
- task.spawn(function()
- local timeLeft = timer
- while timeLeft > 0 and not timersEnded and voteCount < maxVotes do
- wait(1)
- timeLeft = timeLeft - 1
- countdownLabels[option]:setText("⏱️ " .. timeLeft)
- SoundService.playSound(SoundType.COUNTDOWN_TICK, votePosition)
- end
- if not timersEnded then
- countdownLabels[option]:destroy()
- timerEndCount = timerEndCount + 1
- if timerEndCount == 3 then
- checkForWinner()
- end
- end
- end)
- local promptPosition = votePosition + Vector3.new(0, 3, 0)
- local prompt = PromptService.createPrompt()
- prompt:setPosition(promptPosition)
- prompt:setActivationDistance(5)
- prompt:setHoldDuration(0.5)
- prompt:setObjectText(option)
- prompt:setActionText("Vote")
- promptList[option] = prompt
- prompt:onActivated(function(player)
- if alreadyVoted[player.userId] then
- MessageService.sendError(player, "Remove " .. option .. " vote.")
- local previousVote = alreadyVoted[player.userId]
- voteCount = voteCount - 1
- voteLabels[previousVote]:setText(tostring(voteCount) .. "/" .. tostring(maxVotes))
- alreadyVoted[player.userId] = nil
- if previousVote == "cave" then
- caveVotes = caveVotes - 1
- elseif previousVote == "desert" then
- desertVotes = desertVotes - 1
- elseif previousVote == "land" then
- landVotes = landVotes - 1
- end
- else
- if voteCount < maxVotes and not timersEnded then
- voteCount = voteCount + 1
- voteLabels[option]:setText(tostring(voteCount) .. "/" .. tostring(maxVotes))
- alreadyVoted[player.userId] = option
- MessageService.sendInfo(player, "You voted for " .. option .. ".")
- if option == "cave" then
- caveVotes = caveVotes + 1
- elseif option == "desert" then
- desertVotes = desertVotes + 1
- elseif option == "land" then
- landVotes = landVotes + 1
- end
- if caveVotes == maxVotes or desertVotes == maxVotes or landVotes == maxVotes then
- checkForWinner()
- end
- end
- end
- end)
- end
- local function createResetPrompt(resetPosition)
- local prompt = PromptService.createPrompt()
- prompt:setPosition(resetPosition)
- prompt:setActivationDistance(5)
- prompt:setHoldDuration(0)
- prompt:setObjectText("Reset")
- prompt:setActionText("Reset Voting")
- prompt:onActivated(function(player)
- if reset == false then
- MessageService.sendError(player, "Wait till voting ends ")
- else
- timersEnded = false
- voteCount = 0
- alreadyVoted = {}
- for _, label in pairs(countdownLabels) do
- if label then
- label:destroy()
- end
- end
- for _, prompt in pairs(promptList) do
- if prompt then
- prompt:destroy()
- end
- end
- countdownLabels = {}
- voteLabels = {}
- promptList = {}
- createVoteUI(Vector3.new(207, 63, 216), "cave", "11467634330")
- createVoteUI(Vector3.new(222, 63, 216), "desert", "11467634330")
- createVoteUI(Vector3.new(237, 63, 216), "land", "11467634330")
- reset = false
- timerEndCount = 0
- end
- end)
- end
- local vote1Position = Vector3.new(207, 63, 216)
- local vote2Position = Vector3.new(222, 63, 216)
- local vote3Position = Vector3.new(237, 63, 216)
- -- where the prompts will spwwn at
- local vote1MapId = "11467634330"
- local vote2MapId = "11467634330"
- local vote3MapId = "11467634330"
- -- your maps image ids here
- createVoteUI(vote1Position, "cave", vote1MapId)
- createVoteUI(vote2Position, "desert", vote2MapId)
- createVoteUI(vote3Position, "land", vote3MapId) -- map names
- createResetPrompt(Vector3.new(219, 66, 234))
- task.spawn(function()
- wait(timer + 1)
- if not timersEnded then
- checkForWinner()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement