Teleporter Barrier Assistance

What I’m Trying To Achieve

I have 4 walls surrounding my spawn area like so:

I want to make it so that when the player touches one of these walls, they will instantly be teleported back to that center circle there.

These are where the walls are:
image

And this is where the circle is:
image

My Issue

I am having trouble executing what I want to do.
I have the script as a Local Script inside StarterPlayerScripts.
Should it be somewhere else?

This is the code that I have:

local bar = game.Workspace.NewObby.SpawnArea["Spawn Walls"]:GetChildren()
local spawnPad = game.Workspace.NewObby.SpawnArea["Spawn Pad"]["Pad_Piece Top"]

bar.Touched:Connect(function(hit)
	local beenHit = hit.Parent:FindFirstChild('HumanoidRootPart')
	
	if beenHit then
		beenHit.CFrame = spawnPad.CFrame + Vector3.new(0, 5, 0)
	end
end)

The script location is fine, but I suggest using different code.
Maybe try this?

local SpawnArea = workspace:WaitForChild("NewObby").SpawnArea
local Walls = SpawnArea["Spawn Walls"]
local SpawnLocation = SpawnArea["Spawn Pad"]["Pad_Piece Top"]

for i, Wall in pairs(Walls:GetChildren()) do
	Wall.Touched:Connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
			Hit.Parent.PrimaryPart.CFrame = SpawnLocation.CFrame + Vector3.new(0, 5, 0)
		end
	end)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.