How would I make a player teleport randomly between these 5 parts randomly on touch?

Edit: Thank you to those who helped me with this, I appreciate it

Make A Folder. Store all of the Parts inside the Folder And then
Check on this Script.

local AllPartsFolder =  -- Define the Folder u Created
local Part = script.Parent -- Define the Touch Part

local TouchDebounce = false

Part.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") and TouchDebounce == false then
         local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
         if Player then -- Valid Player Touched It
              TouchDebounce = true
              local FolderChildren = AllPartsFolder:GetChildren()
              local Index = math.random(#FolderChildren)
              local Instance = FolderChildren[Index]
               
              Hit.Parent:MoveTo(AllPartsFolder:FindFirstChild(Instance.Name).Position)
              wait(1)
              TouchDebounce = false
         end 
    end
end)

Make sure All Parts are Named Different and Are Stored inside the Folder.

2 Likes

let me see your explorer inside workspace if you still having issue

image

did you define the folder on line 1 as Forceman mentioned?
You probably did not define the variable on line 1 .

You need to put the script inside all 5 parts. Not in the folder.

1 Like

the script must inside the Part not Folder and I rewrote this script:

local AllPartsFolder = script.Parent.Parent -- Define the Folder u Created
local Part = script.Parent -- Define the Touch Part

local TouchDebounce = false

Part.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and TouchDebounce == false then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Player then -- Valid Player Touched It
			TouchDebounce = true
			local FolderChildren = AllPartsFolder:GetChildren()
			local Index = math.random(#FolderChildren)
			local Instance = FolderChildren[Index]

			Hit.Parent:MoveTo(AllPartsFolder:FindFirstChild(Instance.Name).Position)
			wait(1)
			TouchDebounce = false
		end 
	end
end)

Make sure all your Part’s name differently

1 Like

For OP, please do not just copy and paste script, instead try examing the error.

2 Likes

I had been trying to solve it, but my understanding of lua is very limited and scripting isn’t necessarily my strong suit either

Well i’m happy your error was solved.
Just as @ItzMeZeus_IGotHacked said,

I Gave The script as an example of what you had to do.

2 Likes