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

Filtering Enabled Teleport script Teleports all players?

Asked by 9 years ago

So I just got done fixing all my Gui's from turning filtering enabled on. Now I'm not sure if this script breaking is a direct result of filtering enabled or if this has always been a problem. I just played my game with friends and when a player touches a brick it teleports all players besides just the one who touched the brick. Here's what I think is the important part of my script.

1Part.Touched:connect(function()
2    local Spawn = game.Workspace.TeleportAndSpawnStorage.RandomFunRoomSpawn
3    for _, player in pairs(game.Players:GetPlayers()) do
4    local Torso = player.Character:WaitForChild("Torso")
5    Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
6    end
7end)

However, because I have no clue what's wrong, here's the whole script.

01local Part = script.Parent
02Part.Touched:connect(function()
03    local Spawn = game.Workspace.TeleportAndSpawnStorage.RandomFunRoomSpawn
04    for _, player in pairs(game.Players:GetPlayers()) do
05    local Torso = player.Character:WaitForChild("Torso")
06    Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
07    end
08        for _, player in pairs(game.Players:GetPlayers()) do
09            if player:FindFirstChild("leaderstats") then
10                if player:FindFirstChild("MemoryGameBeat").Value == false then
11                    player.leaderstats.RoundsBeaten.Value = player.leaderstats.RoundsBeaten.Value + 1
12                    player:FindFirstChild("MemoryGameBeat").Value = true
13                    player.leaderstats.Points.Value = player.leaderstats.Points.Value + 7
14                end
15                if player:FindFirstChild("Backpack") then
View all 29 lines...

Now I'm sure this might not be the most clean script ever, but I really need help. Would making this into a local script help maybe? It's just I have a teleport Gui that teleports all players too and that's a local script so I'm sorta stuck.

1 answer

Log in to vote
2
Answered by 9 years ago

Well, if you look in your small snippet, you can see you have a for loop where you go over each player, and teleport them. If what you wanted was to only teleport the person who touched it, simply remove the loop and figure out what player touched it:

1Part.Touched:connect(function(Part)
2    if not Part then return end
3    local Player = game.Players:getPlayerFromCharacter(Part.Parent)
4    if not Player then return end
5    local Spawn = game.Workspace.TeleportAndSpawnStorage.RandomFunRoomSpawn
6    local Torso = Player.Character:WaitForChild("Torso")
7    Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
8end)
1
Thanks! I feel sorta dumb that I made a mistake like that but oh well. I'm only human. Thanks again (= User#11440 120 — 9y
1
No problem! iconmaster 301 — 9y
Ad

Answer this question