My map picking system is broken

I wanted to make a map picking system that allows players to choose a map to go to. Each map needs 10 players in order to play a different map. But I came across an issue with the player count. When I go to a Teleporter that player count when up by 8 when I am the only player in the teleporter, I went out of the teleporter, the number of player count didn’t decrease. So I tried making it detect only the HumanoidRootPart but the same number when up, I jumped inside the teleporter and it also went up. I’m getting angry, I’m losing my motivation to work on this project.
If you have any solutions please reply down below

Code:

for i,Part in pairs(workspace.Maps:GetChildren()) do
	if(Part:IsA("Part")) then
		Part.Touched:Connect(function(hit)
			if (game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)) then
				local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.HumanoidRootPart)
			
				if(Part.Name == "TeleportMagic1") then
					if workspace.Maps.TeleportMagic1.Touched:Connect() then
						workspace.MapUpVote.Map1.Value = workspace.MapUpVote.Map1.Value + 1
					elseif workspace.Maps.TeleportMagic1.TouchEnded:Connect() then
						workspace.MapUpVote.Map1.Value = workspace.MapUpVote.Map1.Value - 1
					end
					
				elseif(Part.Name == "TeleportMagic2") then 
					if workspace.Maps.TeleportMagic2.Touched:Connect() then
						workspace.MapUpVote.Map2.Value = workspace.MapUpVote.Map2.Value + 1
					elseif workspace.Maps.TeleportMagic2.TouchEnded:Connect() then
						workspace.MapUpVote.Map2.Value = workspace.MapUpVote.Map2.Value - 1
					end
					
				elseif(Part.Name == "TeleportMagic3") then 
					if workspace.Maps.TeleportMagic3.Touched:Connect() then
						workspace.MapUpVote.Map3.Value = workspace.MapUpVote.Map3.Value + 1
					elseif workspace.Maps.TeleportMagic3.TouchEnded:Connect() then
						workspace.MapUpVote.Map3.Value = workspace.MapUpVote.Map3.Value - 1
					end
				end
			end
		end)
	end
end

The errors I got was attempt to call a nil value and Attempt to connect failed: Passed value is not a function

I was going to say “You are not passing any function into the Touched event”, within your if statements…
However I think it may be more of a problem with the nested Connects which may be unnecessary. Try separating out the Touched:Connect and Toucheended:connects in to separate events

local mapVotes = {map1 = 0, map2 = 0, map3 = 0}

for i,Part in pairs(workspace.Maps:GetChildren()) do
	if(Part:IsA("Part")) then
		Part.Touched:Connect(function(hit)
		-- Insert checks to see if "hit" is a Player
			if Part.Name == "TeleportMagic1" then
				map1 +=1
			elseif Part.Name == "TeleportMagic2" then
				map2 +=1
			elseif Part.Name == "TeleportMagic3" then
				map3 +=1
			end
		end)
		Part.TouchEnded:Connect(function(hit)
		-- Insert checks to see if "hit" is a Player
			if Part.Name == "TeleportMagic1" then
				map1 -=1
			elseif Part.Name == "TeleportMagic2" then
				map2 -=1
			elseif Part.Name == "TeleportMagic3" then
				map3 -=1
			end
		end)
	end
end

I’m have not tested that in Studio, it seems a more logical way to check

1 Like

It fixes the jumping, and decrease in value part but, it still when up by 8.

Can i ask whats wrong with my script when i try to play i didnt teleport to GameAreaSpawn

Lol Finally I solved my own problem thx.
i just changed InRound To BoolValue.