Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Filtering Enabled Teleport script Teleports all players?

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.

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

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

local Part = script.Parent
Part.Touched:connect(function()	
	local Spawn = game.Workspace.TeleportAndSpawnStorage.RandomFunRoomSpawn
	for _, player in pairs(game.Players:GetPlayers()) do
	local Torso = player.Character:WaitForChild("Torso")
	Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
	end
		for _, player in pairs(game.Players:GetPlayers()) do
			if player:FindFirstChild("leaderstats") then
				if player:FindFirstChild("MemoryGameBeat").Value == false then
					player.leaderstats.RoundsBeaten.Value = player.leaderstats.RoundsBeaten.Value + 1
					player:FindFirstChild("MemoryGameBeat").Value = true
					player.leaderstats.Points.Value = player.leaderstats.Points.Value + 7
				end
				if player:FindFirstChild("Backpack") then
					player.Backpack.RemoteClient.ChangeGui:FireClient(player)
				end
				player.PlayerSoundFolder.MemoryGameLevelOneWinnerSound:Play()
				wait(43)
				local Spawn = game.Workspace.TeleportAndSpawnStorage.TeleportSpawn
				for _, player in pairs(game.Players:GetPlayers()) do
					local Torso = player.Character:WaitForChild("Torso")
					Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
				end
				wait(10.5)
				player.PlayerSoundFolder.MemoryGameLevelOneWinnerSound:Stop()
			end
		end
	end)

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

✓ Accepted answer

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:

Part.Touched:connect(function(Part) 
	if not Part then return end
	local Player = game.Players:getPlayerFromCharacter(Part.Parent)
	if not Player then return end
	local Spawn = game.Workspace.TeleportAndSpawnStorage.RandomFunRoomSpawn
	local Torso = Player.Character:WaitForChild("Torso")
	Torso.CFrame = CFrame.new(Spawn.Position + Vector3.new(0, 2 ,0))
end)

2 comments

1

Thanks! I feel sorta dumb that I made a mistake like that but oh well. I'm only human. Thanks again (=

1

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.