Need help with a teleport script

I want to a make script that if you stand on a part you get teleported to a minigame in the map after 20 seconds (I just want to create a ‘queue’ with wait(20) . But I want the script to have a limit of 8 different player touches because I don’t want more than 8 people in that minigame at the same time. I need the script to start a cooldown of 120 seconds after the players that stood on the part got teleported. After that cooldown it can be touched by < 8 players again . The teleport and the cooldown also has to work after 20 seconds ‘queue’ if only 1 player touches the part. So it has to be in a loop. I searched for more than 8 hours on google but couldn’t find anything. If you have any questions, please reply. I hope someone can help me.

Note: I want players to teleport within the same server. So no game id’s or anything. Just the same server as the lobby is in.

note2: I’m at work so i will reply after 19:30 cest

This is what I’ve tried, but couldn’t figure out how to make it work as I described above. (It would just allow people to sometimes teleport and sometimes have a cooldown for unknown time period even when changing the values.)

local tagg=0
local plrs={}
Workspace.patat.Touched:connect(function(hot)
	local plr = game.Players:GetPlayerFromCharacter(hot.Parent)
	if tick()-tagg 120 then
		return end

	if plr then
		plr.Character.HumanoidRootPart.CFrame = CFrame.new(-54.936, 0.5, 100.038)
	end
	if plr then
		if not plrs[plr] and #plrs <8 then
			table.insert(plrs,plr)
			if #plrs == 8 then
				tagg=tick()
			end
		end
	end
end)

image_2021-10-01_163529
This is the part. It’s in workspace. The other 4 grey scripts are disabled.

1 Like

I don’t see a 20 second wait in your script anywhere. It looks like it will just teleport the player instantly. I don’t think this means anything:

Did you forget the greater than symbol > (or less than) not sure what you’re trying to do there.

You’re teleporting the player before you even add them to the player list/counter. You probably need another generic debounce too, because ‘touched’ will trigger many times per second when players touch the part.

You should probably build your player list and start a 20 second timer (delay function maybe?). Then when the 20 seconds is up, loop through the list of players teleporting them, then clear out your player list and record the time for your 120 second cool down.

2 Likes

Will look into this tomorrow. Thanks for now :slight_smile:

1 Like