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,
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 -- 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!
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!