Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to combine these two scripts?

Asked by 5 years ago
Edited 5 years ago

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

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

1local 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.

0
So you want to figure out how to stop teleporting players after a limit? develop_d 53 — 5y
0
I'm working on a script for ^^^^ right now develop_d 53 — 5y

2 answers

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

01local teleportTo = game.Workspace.Part --What part you teleport to. Change this to whatever part you want to teleport to.
02local numTeleportedPlayers = 0
03local canTeleport = true --boolean for if more players can / cannot be teleported
04PLAYERS_TELEPORTED_LIMIT = 2; -- specify the max number of players that can be teleported here
05 
06function OnTouched(part)
07    -- part.Parent:MoveTo(teleportTo.Position)
08    --^^^^ is deprecated, use the below:
09 
10    if(part.Parent:FindFirstChild("HumanoidRootPart")and canTeleport == true)then
11        part.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportTo.Position)
12    end
13    numTeleportedPlayers = numTeleportedPlayers + 1
14end
15 
View all 21 lines...

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:

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

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

1if(part.Parent:FindFirstChild("HumanoidRootPart") and canTeleport == true and not teleportingPlayers[part.Parent.Name])then
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. develop_d 53 — 5y
0
oops, it happens. there's not just one solution to a problem, so good to have multiple royaltoe 5144 — 5y
0
Wow thank you.. TheMostDelikanliMan -14 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

01cantp = true
02limit = 5
03current = 0
04teleto = game.Workspace.oturak
05PART = game.Workspace["Your Part's name / Part the player must touch(must be in workspace)"]
06 
07game.Players.PlayerAdded:Connect(function(plr)
08    PART.Touched:Connect(function(part)
09        if part.Parent.Name == plr.Name then
10            if current <= limit then
11                if cantp then
12                    part.Parent.HumanoidRootPart.CFrame = teleto.CFrame + Vector3.new(0, 4, 0)
13                    current = current + 1
14                    cantp = false
15                    wait(0.1)
View all 23 lines...

Answer this question