My Teleport script won't work properly

Hello. I was making a roblox game, but i was stuck on one part, where the tp script won’t work. Here is the problem: Fiksavimas

I dont understand why you are saying game.Parent.OnTouch().

But from your script it looks like you want to teleport every player in the game.

To do that you could just do:

script.Parent.ClickDetector.MouseClick:Connect(function()
	for i, player in pairs(game.Players:GetPlayers()) do
		if player.Character.HumanoidRootPart then
			player.Character.HumanoidRootPart.CFrame = CFrame.new()
		end
	end
end)

Also, this is some more information:Fiksavimas

Could you explain what you want?

Also have you tried my code?

I want so when you click on a part, it teleports you to another part.

Like @SpacialEthanRB mentioned, you can’t do game.Parent.Players as there is no parent for the game. Instead you have to use a loop to get all players in the game which you can do using the code given above.

Then just do:

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	if player.Character.HumanoidRootPart then
		player.Character.HumanoidRootPart.CFrame = Part.CFrame
	end
end)

Still doesn’t work. Any other scripts?

Can you explain why it doesn’t work?

Any errors?

It does show some errors on player.Character and Part.CFrame

You have to reference the part.

Also can you send a picture of the console

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player.Character.HumanoidRootPart then
		player.Character.HumanoidRootPart.CFrame = script.Parent.Teleport1.CFrame
	end
end)

The player from the parameter is Capitalised

I put the parameter as Player and I used player which is my bad but you should have just changed it.

You can’t just say Teleport1 because how is the script suppose to know what that is you have to reference it

Okay. Any picture on how it looks like?

Try it now:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player.Character.HumanoidRootPart then
		player.Character.HumanoidRootPart.CFrame = script.Parent.Teleport1.CFrame
	end
end)

Doesn’t teleport me to the other part.

Another thing I see is that ‘script.Parent.Teleport1’ isn’t the correct location of the Teleport1 part, it should be:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player.Character.HumanoidRootPart then
		player.Character.HumanoidRootPart.CFrame = script.Parent.Parent.Teleport1.CFrame
	end
end)

I have been asking you what is the problem, it makes it really hard to help someone if they don’t tell you why.

I also suggest you have the script inside the model and not in one part.