Hello! I am trying to make something that teleports players to another place, and only starts when enough people have touched a part. I'm using a global value to copy this on to other parts and have a display that shows the player count. When I touch it, instead of the player count staying at 1, everytime I move it goes up, which I've been trying to fix for so long. I've tried everything, and this script is my most recent version of the script. Can somebody help me with what I'm doing wrong?

local TeleportService = game:GetService("TeleportService")
local GameID = 5948456863

local PlayerCount = game.ReplicatedStorage.PlayerCount
local PlayerTable = {}

script.Parent.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	 
	local PlayerInTable = false
	
	if Player then
		for i, v in pairs(PlayerTable) do
			print("got to i, v")
			if v == Player then
				PlayerInTable = true
				print("in table")
			end
		end
		
		if PlayerInTable == true then
			print("IN TABLE")
		elseif PlayerInTable == false then
			PlayerCount.Value = PlayerCount.Value + 1
		end
	end
end)

PlayerCount.Changed:Connect(function()
	print(PlayerCount.Value)
end)

2 comments

0

Use a Region3.

0

I've already fixed this using something else, but thanks