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

How would i make a Skip elseif do Teleport?

Asked by
Aozwel 71
4 years ago
Edited 4 years ago

Hey there,

Im trying to make a teleporter that force teleports all players who HAVEN'T Touched X part?

Wondering on how i would do that,

So if the player has Touched the Part he doesn't get effected by the Force teleport,

local part = workspace.ForceTele

script.Parent.Touched:Connect(function(hit)
    local plrName = hit.Parent.Name
    pcall(function() --Just in case something else that's not a player touches the block
        game.Players[plrName].TouchedPart.Value = true
    end)
end)

wait(10)

for i,v in next, game.Players:GetPlayers() do 
 local chr = v.Character 
    if chr and chr:FindFirstChild("HumanoidRootPart") then  
        chr:SetPrimaryPartCFrame(part.CFrame) 
    end
end

Thanks,

2 answers

Log in to vote
1
Answered by
Ankur_007 290 Moderation Voter
4 years ago

Let's break your problem into some steps:

  1. Add a .Touched connection to X part for players who will not be teleported

  2. Affect the status of this player's teleportation

  3. Teleport all players who's status remains unchanged

We can use dictionaries to make our task easier


Part 1:

local exempt = YourXPartHere 
local players = game:GetService("Players")

exempt.Touched:Connect(function(part)
    if players:GetPlayerFromCharacter(part.Parent) then
        -- Change status
    end
end)

Part 2: Since we need to change the status of teleportation and it needs to be linked to the actual teleport part, we'll come back to this after 3

Part 3:

local part = workspace.ForceTele

local function Teleport(list)
    for i,v in next, list do 
        local chr = v.Character 
        if chr and chr:FindFirstChild("HumanoidRootPart") then  
            chr:SetPrimaryPartCFrame(part.CFrame) 
        end
    end
end

Now, we need to make list exclude all our exempted players, so we make a dictionary for that:

local excluded = {}

Incorporate excluded into the .touched connection:

local excluded = {}
local exempt = YourXPartHere 
local players = game:GetService("Players")

exempt.Touched:Connect(function(part)
    local player = players:GetPlayerFromCharacter(part.Parent)
    if player and not excluded[player] then
        -- Change status
        excluded[player] = true
    end
end)

And finally we update our list:

local function GetList()
    local players = game.Playere:GetPlayers()
    for index, player in pairs(players) do
        if excluded[player] then
            players[index] = nil
        end
    end
    return players
end)

Our final functioning script:

local excluded = {}
local exempt = YourXPartHere 
local players = game:GetService("Players")
local part = workspace.ForceTele

exempt.Touched:Connect(function(part)
    local player = players:GetPlayerFromCharacter(part.Parent)
    if player and not excluded[player] then
        excluded[player] = true
    end
end)

local function GetList()
    local players = game.Players:GetPlayers()
    for index, player in pairs(players) do
        if excluded[player] then
            players[index] = nil
        end
    end
    return players
end)

local function Teleport(list)
    for i,v in next, list do 
        local chr = v.Character 
        if chr and chr:FindFirstChild("HumanoidRootPart") then  
            chr:SetPrimaryPartCFrame(part.CFrame) 
        end
    end
end

-- Wherever you need to teleport 
Teleport(GetList())

That's the basic structure of the script, you just need to know how to implement it (call what when where) Excuse the explanation, I'm a bit annoyed on phone and didn't use a lot of markup. Feel free to point out any mistake or ask a question in the comments!

Ad
Log in to vote
1
Answered by
sheepposu 561 Moderation Voter
4 years ago

Give the players a bool value called "TouchedPart". When the part is touched a script inside of it will make TouchedPart true on the player. The script will look like this

script.Parent.Touched:Connect(function(hit)
    local plrName = hit.Parent.Name
    pcall(function() --Just in case something else that's not a player touches the block
        game.Players[plrName].TouchedPart.Value = true
    end)
end)

Then when it is time to teleport, for every player in the game, if they do not have that value as true, then teleport them.

Hope this helps!

0
So i just insert this code into a LocalScript in the Part? Aozwel 71 — 4y
0
Got it to work, Thanks alot! Aozwel 71 — 4y
0
I doesn't seem to teleport the 2nd player if they didn't?, Do i make it a localscript or normal? Aozwel 71 — 4y
0
This above should be a normal script under the part, that way the value changes server-wide sheepposu 561 — 4y
View all comments (7 more)
0
It's also possible that the 2nd player is not teleporting due to a mistake in the script teleporting. It should be a ServerScript in ServerScriptService sheepposu 561 — 4y
0
So i just put this code into Script in ServerScriptService? Check edited original post for code, Aozwel 71 — 4y
0
Didn't see your other comment, One sec Aozwel 71 — 4y
0
No, the code above is for the part. I didn't provide any code for the ServerScriptService. It's pretty similar to the code you presented, so I'm going to leave you to figure it out sheepposu 561 — 4y
0
Yeah i just did that, Teleports me even if i touch it now? Aozwel 71 — 4y
0
Could you post a new question about it and present all the new code and everything to make this easier sheepposu 561 — 4y

Answer this question