Teleporting Not Working

So I have been making a sword fight game with random event happening every 10 seconds, and one of the event you have to complete an obby to go back to the fighting arena. I have made a script which teleports you to the obby, which is running just fine, the only problem I have is that the game wouldn’t make the player teleport back to the fighting arena, nor killing the player when touched. Being the new scripter I am, I’m pretty confused on why it’s not working. Can somebody tell me what I am doing wrong? Thanks for reading.

obby

1 Like
  1. Use PivotTo(CFrame) to teleport.
  2. What is ‘player’? You’re using a .Touched event, you can get the player by it. [If you provide a parameter in the function].
1 Like

how could i use a pivotto(CFrame) in this situation? I never heard of it so i do not know how to use it.

1 Like

Example of using PivotTo: would be

player.Character:PivotTo(Spawnn.CFrame)

I have tried out your suggestion and it doesn’t seem to work.

You should clone the obby first because when you declare your variables, it is still pointing to the obby inside the server storage. After you have cloned it, use the clone as a pointer in declaring your variables.

KillParts returns a table so it is required that you use a for loop to loop through the table and add a connection for each killpart

Again, the Available variable returns a table so you should index the table using a random number generator via Random.new():NextInteger(min, max) using 1 as the minimum, and the total number of items in the Available table.

After killing the player or teleporting the player, you must destroy the cloned obbygame to prevent memory leaks

local ObbyGame = game:GetService("ServerStorage").ObbyGame:Clone()
local Spawn = ObbyGame:FindFirstChild("Spawn")
local Teleport = ObbyGame:FindFirstChild("ObbySpawnPoint")
local KillParts = ObbyGame:FindFirstChild("KillParts"):GetChildren()

local BackSpawn = ClonedMap:FindFirstChild("ObbySpawnPoint")
local Available = BackSpawn:GetChildren()

ObbyGame.Parent = workspace
player.Character:FindFirstChild("HumanoidRootPart").CFrame = Spawn.CFRrame

Teleport.Touched:Connect(function()
	player.Character:FindFirstChild("HumanoidRootPart").CFrame = Available[Random.new():NextInteger(1, #Available)].CFrame
	ObbyGame:Destroy()
end)

for i, v in ipairs(KillParts) do
	v.Touched:Coonnect(function()
		player.Character.Humanoid.Health = 0
		ObbyGame:Destroy()
	end)
end
1 Like

Your script of yours seems to work now for my game, thanks a lot for your help!