Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to combine these two scripts?

`local TeleTo = game.Workspace.oturak --What part you teleport to.

function OnTouched(part) part.Parent:MoveTo(TeleTo.Position) end

local teleportedplayers = 0 

local canteleport = true if teleportedplayers > 0 then canteleport = false wait(10) canteleport = true end

script.Parent.Touched:connect(OnTouched)`

The max teleported players thing doesn't work what is my problem? thanks for help.

2 comments

0

So you want to figure out how to stop teleporting players after a limit?

0

I'm working on a script for ^^^^ right now

2 answers

This should teleport a certain amount of players before you want the game to stop teleporting players. Also, the :MoveTo() method you used is depreciated so I used the non deprecated way of doing it. I was just assuming from your code that this is what you wanted to do, if you want the script to do anything else, please say so.

local teleportTo = game.Workspace.Part --What part you teleport to. Change this to whatever part you want to teleport to. 
local numTeleportedPlayers = 0
local canTeleport = true --boolean for if more players can / cannot be teleported
PLAYERS_TELEPORTED_LIMIT = 2; -- specify the max number of players that can be teleported here

function OnTouched(part)
	-- part.Parent:MoveTo(teleportTo.Position)
	--^^^^ is deprecated, use the below:

	if(part.Parent:FindFirstChild("HumanoidRootPart")and canTeleport == true)then
		part.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportTo.Position)
	end
	numTeleportedPlayers = numTeleportedPlayers + 1
end

if numTeleportedPlayers > PLAYERS_TELEPORTED_LIMIT then
	canTeleport = false 
	wait(10) canteleport = true 
end

script.Parent.Touched:connect(OnTouched)

The script currently only checks if the number of players does teleported is too high, it does not check if the player uses the teleporter twice, but it can.

just change 'numTeleportedPlayers' to "teleportedPlayers = {}" and whenever a player teleports, add them to the table by using:

table.insert(teleportedPlayers, part.Parent.Name)

see if the player trying to be teleported has already teleported by adding a check to the following line:

if(part.Parent:FindFirstChild("HumanoidRootPart") and canTeleport == true and not teleportingPlayers[part.Parent.Name])then

3 comments

0

oh sorry I was working on the script while you posted this and now I can't delete it without losing reputation. Anyway both scripts do the same thing differently.

0

oops, it happens. there's not just one solution to a problem, so good to have multiple

0

Wow thank you..

Put this script in ServerScriptService and change the "" in PART to the part's name.

cantp = true
limit = 5
current = 0
teleto = game.Workspace.oturak
PART = game.Workspace["Your Part's name / Part the player must touch(must be in workspace)"]

game.Players.PlayerAdded:Connect(function(plr)
	PART.Touched:Connect(function(part)
		if part.Parent.Name == plr.Name then
			if current <= limit then
				if cantp then
					part.Parent.HumanoidRootPart.CFrame = teleto.CFrame + Vector3.new(0, 4, 0)
					current = current + 1
					cantp = false
					wait(0.1)
					cantp = true
				else
					print("Not yet")
				end
			end
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.