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

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.

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.

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

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)

Answer this question