Let's break your problem into some steps:
Add a .Touched connection to X part for players who will not be teleported
Affect the status of this player's teleportation
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
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
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
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!
11 comments
So i just insert this code into a LocalScript in the Part?
Got it to work, Thanks alot!
I doesn't seem to teleport the 2nd player if they didn't?, Do i make it a localscript or normal?
This above should be a normal script under the part, that way the value changes server-wide
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
So i just put this code into Script in ServerScriptService? Check edited original post for code,
Didn't see your other comment, One sec
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
Yeah i just did that, Teleports me even if i touch it now?
Could you post a new question about it and present all the new code and everything to make this easier
https://scriptinghelpers.org/questions/84978/teleport-all-players-unless-touched-part