What is wrong with my teleport command script?

I’m trying to make a teleport command and it goes like this…

Player types; “!tp Player1 Player2”, Player1 will be teleported to Player2.

I tested it with a friend and it doesn’t work. Send help, thanks much!

local command = "!tp"

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()

	plr.Chatted:Connect(function(msg)
		local splitmsg = string.split(msg, " ")

		if splitmsg[1] == command then
			local hrp1 = workspace:FindFirstChild(splitmsg[2]):WaitForChild("HumanoidRootPart")
			local hrp2 = workspace:FindFirstChild(splitmsg[3]):WaitForChild("HumanoidRootPart")

			hrp1.Position = hrp2.Position
		end
	end)
end)
1 Like

Hey there! You’re not using string.split correctly.

You should use: local splitMsg = msg:split(" ")

hrp1.Position = hrp2.Position

There, hrp2.Position, should be using CFrame
Like, CFrame.new(hrp2.Position)

But I don’t think the way you scripted I suggest look at YouTube and there is plenty hints how to make commands. The one I learned before: MAKE ADMIN COMMANDS - Roblox Scripting Tutorial (Advanced) - YouTube

Good luck!

Position would also work just fine. The issue is the split methode I beleive, I could be wrong.

The way they used split is correct, you don’t have to use the method on a string

Oh alright, thanks for correcting me. Not too familiair with that methode.

I wonder what What’s the issue then ;-;