Help fixing script!

So basically I was trying to make a voting system compatible with the round script, but now it broke th round script, and I added print statements, it doesn’t print “Hi2”, “C”, or “T”

-- Local script in voting frame
local Classic = game.ReplicatedStorage.Classic
local Teams = game.ReplicatedStorage.Teams
local VotingOn = game.ReplicatedStorage.VotingOn
local status = game.ReplicatedStorage.VotingStatus
local Vote = game.ReplicatedStorage.Vote
local chosen

script.Parent.Classic.MouseButton1Click:Connect(function()
    if chosen ~= "Classic" then
       game.ReplicatedStorage.Vote:FireServer(chosen, "Classic")
       chosen = "Classic"
       script.Parent.Visible = false
    end
end)

script.Parent.Teams.MouseButton1Click:Connect(function()
    if chosen ~= "Teams" then
        game.ReplicatedStorage.Vote:FireServer(chosen, "Teams")
        chosen = "Teams"
        script.Parent.Visible = false
    end
end)

while wait() do
   script.Parent.Classic.TextLabel.Text = Classic.Value .." Votes"
   script.Parent.Teams.TextLabel.Text = Teams.Value .." Votes"
end
-- script in serverscriptservice, used also for the voting system
game.ReplicatedStorage.Vote.OnServerEvent:Connect(function(player, previous, chosen)
    local votes = game.ReplicatedStorage[chosen]
    votes.Value = votes.Value + 1
    if previous ~= nil then
       local prev = game.ReplicatedStorage[previous]
       prev.Value = prev.Value - 1
    end
end)

for i = 10,1,-1 do
   game.ReplicatedStorage.VotingStatus.Value = i .." seconds to vote"
   wait(1)
end
local votes = {game.ReplicatedStorage.Classic, game.ReplicatedStorage.Teams}
table.sort(votes, function(a,b)
   return a.Value > b.Value 
end)
local chosen = votes[1].Name
if chosen == "Classic" then
   print("Classic")
   game.ReplicatedStorage.WhichGamemode:Invoke(chosen)
   print("C")
else
   print("Teams")
   game.ReplicatedStorage.WhichGamemode:Invoke(chosen)
   print("T")
end
-- Another script in serversciptservice for rounds
repeat wait()until #game.Players:GetPlayers() >= 1
local text = game.ReplicatedStorage.Value
local Maps = game.ServerStorage:GetChildren()


function Intermission()
    game.ReplicatedStorage.ShowVotes:FireAllClients()
	workspace.Sound1:Play()
		for i = 10,1,-1 do
			text.Value = "Intermission "..i
			wait(1)
		end
	
	print("Yay")
	game.ReplicatedStorage.Function:Fire()
	print("yay2")
end

Intermission()

game.ReplicatedStorage.Function2.Event:Connect(function()
print("Hi")
local function Gamemode() 
wait()  
game.ReplicatedStorage.WhichGamemode.OnInvoke = function(chosen)
print("Hi2")
               print(chosen)
           if chosen == "Teams" then
                print("Teams")
           else
             print("Classicaa")
           end

			wait(5)

local function Gamemode() 
wait()  
game.ReplicatedStorage.WhichGamemode.OnInvoke = function(chosen)
print("Hi2")
   game.Workspace.Sound1:Stop()
   local ChosenMap = Maps[math.random(1,#Maps)]:Clone()
print(ChosenMap)
ChosenMap.Parent = workspace
ChosenMap.Name = "LoadedMap"
    for _, player in pairs(game.Players:GetChildren()) do
    local char = player.Character
    char.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LoadedMap").SpawnPlayersToMap.CFrame
end
wait()
game.Workspace:WaitForChild("LoadedMap").Sound:Play()
for _, player in pairs(game.Players:GetPlayers()) do
   
end
for i = 5,1,-1 do
   text.Value = ("Round Starting in ".. i)
   wait(1)
end
for _, player in pairs(game.Players:GetChildren()) do
   local sword = game.ReplicatedStorage.ClassicSword:Clone()
   sword.Parent = player.Backpack
   sword = game.ReplicatedStorage.ClassicSword:Clone()
   sword.Parent = player.StarterGear
end
for i = 6,1,-1 do
   text.Value = (i)
   wait(1)
if i == 1 then
for _, player in pairs(game.Players:GetChildren()) do
    local sword = player.Backpack:FindFirstChild("ClassicSword")
    local sword2 = player.StarterGear:FindFirstChild("ClassicSword")
    local char = player.Character
    if sword then sword:Destroy() end
    if sword2 then sword2:Destroy() end
if char then
    local sword = char:FindFirstChild("ClassicSword")
    if sword then sword:Destroy() end
end
end
for _, player in pairs(game.Players:GetChildren()) do
   if player.Backpack:FindFirstChild("AzureSword") == true or player.StarterGear:FindFirstChild("AzureSword") then
    player.Character:FindFirstChild("AzureSword"):Destroy()
    player.Backpack:FindFirstChild("AzureSword"):Destroy()
    player.StarterGear:FindFirstChild("AzureSword"):Destroy()
end
end
   local function GetPlayerWithMostKills()
    local Current, Plr = -1, nil;

    for _, Player in ipairs(game:GetService("Players"):GetPlayers()) do --// ipairs is good for arrays; i++ order
        if (Player.leaderstats.Kills.Value > Current) then
            Plr = Player;
            Current = Player.leaderstats.Kills.Value; --// Assign it to the highest found
            
        end
    end

    return Plr, Current;
end

   local Players = game:GetService("Players")
   local player = Players.LocalPlayer    
   local PlayerWithMostKills, Kills = GetPlayerWithMostKills();
   print(PlayerWithMostKills)
   
 
-- Fetch the thumbnail
local userId = PlayerWithMostKills.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Dictionary = {
    Player = PlayerWithMostKills;
    Kills = Kills;
    Content = content;
}
ReplicatedStorage.ShowNameAndKills:FireAllClients(Dictionary);
ReplicatedStorage.ShowImage:FireAllClients()

-- Set the ImageLabel's content to the user thumbnail
for _,player in ipairs(game.Players:GetChildren()) do
local imageLabel = player.PlayerGui.MostKills.Frame.PlrImage
imageLabel.Image = content
imageLabel.Size = UDim2.new(0, 166,0, 154)
end

   wait(5)
   game.ReplicatedStorage.CloseImage:FireAllClients()
   game.Workspace:WaitForChild("LoadedMap").Sound:Stop()
   for _, player in pairs(game.Players:GetChildren()) do
   local char = player.Character
   char.HumanoidRootPart.CFrame = game.Workspace:WaitForChild("LobbySpawnPart").CFrame
end
   game.Workspace:WaitForChild("LoadedMap"):Destroy()
   for _, player in pairs(game.Players:GetChildren()) do
      if player.leaderstats.Kills.Value > 0 then
        player.leaderstats.Kills.Value = 0
      end
   end
   Gamemode()
   end
end
end
end   
end
end
end)

Thanks, and feel free to ask questions

5 Likes

Try adding prints to the other parts of the code before the prints you mentioned. This way, we can see where the code isn’t working.

4 Likes

Hi! I made a game with voting system too. Click here to check this out so you know what I’m talking about. You have to visit it with 2 of your friends too, so the round can start and you can see map voting system.

Visited? You know how everything works? Let’s get started then.

I have made a Round Script that is located in ServerScriptService. In the Round Script there is folder called ‘Configurations’. In Configurations I have got 2 IntValues representing (with their name) votes on each map. When there are 3 players in the round it starts. After intermission you can pick your favourite map. How does it work? The answer is: pretty simple! In StarterGui I have map voting GUI. It have 2 buttons: one WoodMapVoteButton and second one VillageMapVoteButton. In this GUI there is also Data Folder with String Value that represents the map that you voted on. When intermission ends and there is map voting time MapVote GUI shows. When you click on the map it saves the data to the Folder. When you didn’t vote it just leaves your value blank and makes the GUI invisible after 10 seconds. Then in the Round Script it loops through all players, and check’s what is the value of their vote. If it’s WoodMap, it gives one point to ServerScriptService>Round Script>Configurations>WoodMapVotes. If it’s VillageMap it does the same but with village map votes. If you didn’t vote it doesn’t give the point to any maps. When all is done (all votes have been count) we have got 3 things that can happen. We can have a tie, Wood Map win, Village Map win. If it’s a tie, or no players have answered the vote question, game picks random map and teleports all players there. If it’s Wood Map it teleports all players to it, and the same thing happens when it’s Village Map. After teleportation, game.ServerScriptService[“Round Script”].Configurations.WoodMapVotes and VillageMapVotes resets. Also player vote Data Value resets too so the player can vote in the next round.

I hope that I helped. If yes please mark this as a Solution and give my comment the :heart: if you want.

5 Likes

here you end the if function but not the
game.ReplicatedStorage.Function2.Event:Connect(function()

2 Likes

The variable chosen is undefined meaning it return nil so the params you are giving to your remote event are nil, “mapname”.

2 Likes

It is defined here…

2 Likes

It is not defined in the code you have on the topic.

1 Like

Also here…

1 Like

If this event were to fire before the wait sequence it would send nil, “Classic”
I recommend fixing this because if someone has an autoclicker spamming it they may brake the voting system.

1 Like

I followed this tutorial: https://www.youtube.com/watch?v=g6G12e1Fsno

1 Like

So how can I fix that? (30 charssss)

1 Like

I have already tried that, and like I said, it doesn’t print “Hi2”

1 Like

@seancool07777 @WooleyWool @boeljoet and @Jermartynojm I figure something is wrong with my voting script because it is not receiving the remote function, that is invoked on one of my voting scripts

1 Like

I’m not very good in connecting events etc. so I won’t help you. As I said, you can create a Script in the GUI that’s changing your vote data located in player.PlayerGui.VoteGUI.Data on the whole server so Round Script can acess your vote.

1 Like

Add spawn or coroutine function in while loop.

1 Like

For some reason the sound will play, but not stop, could someone help me? This line:

I also tried: workspace.Sound:Stop()

1 Like

In my games when you click on GUI Button it always stops the Click Sound first and then plays it. I do:

local ClickSound = --Location of the sound here.
ClickSound:Stop()
ClickSound:Play()

If you want to use WaitForChild try doing this:

local ClickSound = game.Workspace:WaitForChild("ClickSound")
ClickSound:Stop()
ClickSound:Play()
2 Likes

I want it to stop automatically so that sounds don’t overlap

1 Like

So do what I said. When you want to play the sound stop it first.
And I think that when you try to play sound that is playing it will do nothing- sound will still play at the same position before you played it again, so it won’t overlap and play from the beginning.
To play it from the beggining stop it and play it. It’s my method when for example click sound have 1 second blank audio after click. With this method when player clicks GUI Button, he will always hear a click, not only sometimes.

1 Like

Ok I tried that, but the sound keeps on playing

EDIT: I fixed that, but I want it to repeat and I added a while true at the top of my script, but it repeats at the wrong place

1 Like