Teleport Player Bug

Hello!
I made a teleport system, with a button where the player can click on it. Before, its working, like my player can be teleported at the place i want. But with NO reasons, now, my player cant be teleported.
And the print(test2) dont appear in the output too. Its in normal script ( no local script )

local clickDetector = workspace.Button2.Button.ClickDetector
local EndBlock = workspace.pos


clickDetector.MouseClick:Connect(function(touched)
	print("test")
	if touched.Parent:FindFirstChild("Humanoid") then
		print("test2")
		local char = touched.Parent
		local humanoidRootPart = char.HumanoidRootPart
		print(char)
		print(humanoidRootPart)
		humanoidRootPart.Position = EndBlock.Position
	end
end)

maybe use CFrame and not Position

local clickDetector = workspace.Button2.Button.ClickDetector
local EndBlock = workspace.pos


clickDetector.MouseClick:Connect(function(touched)
	print("test")
	if touched.Parent:FindFirstChild("Humanoid") then
		print("test2")
		local char = touched.Parent
		local humanoidRootPart = char.HumanoidRootPart
		print(char)
		print(humanoidRootPart)
		humanoidRootPart.CFrame = EndBlock.CFrame
	end
end)

Not working … And i still not print the print(“test2”) … I use R6 character btw

MouseClick returns the player who pressed the LCickDetector, you’re using it wrong

Humm … OK. I use what so ? Like i need to find the player and not the character?

so its gonna be like

local humrootpart = touched.Character:FindFirstChild("HumanoidRootPart")
1 Like

Replace touched.Parent with touched.Character, also the if statement is kinda unneeded since a character is always gonna have a humanoid, remove it

1 Like

Its work !!! thank you a lot guys, its been 1h i try to fix it, thank you a lot

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like

Yep ! thank you for your help :stuck_out_tongue:

1 Like

You don’t need to check if it’s a player. A ClickDetector will return the player who pressed the button. So, in this case you code would look something like this:

local clickDetector = game.Workspace.Button2.Button.ClickDetector
local EndBlock = game.Workspace.pos

clickDetector.MouseClick:Connect(function(player)
    local char = player.Character
	local humanoidRootPart = char.HumanoidRootPart
	humanoidRootPart.CFrame = EndBlock.CFrame
end)

Oh really ? i try it right noww

You’re kinda a bit too late on that since the issue is already resolved since it was already found out that it was cause of incorrect parameter usage

1 Like

It’s basically the same thing we already discussed, it’s going to do the same thing

2 Likes