Teleport command has no errors, but its not working!

Hello, developers! So I had taken a script from one of @ItsKoolPlayz’s posts, and tweaked it to be a command in which if you are a certain team, you will be able to use a command to teleport to a spot. The problem is, it doesn’t work, with no errors. Please help me! Code:

local prefix = ":"
local teleportCommand = "to"
local hostTeleport = game.Workspace.HostTeleport
local coHostTeleport = game.Workspace.CoHostTeleport

game:GetService("Players").PlayerAdded:Connect(function(Player)
	if (Player.TeamColor == BrickColor.new("Bright bluish green") or Player.TeamColor == BrickColor.new("Slime green")) then
		Player.Chatted:Connect(function(Message)
			local prefixLength = string.len(prefix)
			if (string.sub(Message, prefixLength + 1)) then
				
				local command = string.sub(Message, prefixLength + 1)
				local splitBySpaces = string.split(command, " ")
				
				if (splitBySpaces[1] == teleportCommand) and (splitBySpaces[2]) then
					if (string.len(splitBySpaces[2]) == "host" and Player.TeamColor == BrickColor.new("Bright bluish green")) then
						local playerToTeleport = Player
						playerToTeleport.Character:FindFirstChild("HumanoidRootPart").CFame = hostTeleport.CFrame
					elseif (string.len(splitBySpaces[2]) == "cohost" and Player.TeamColor ==  BrickColor.new("Slime green")) then
						local playerToTeleport = Player
						playerToTeleport.Character:FindFirstChild("HumanoidRootPart").CFame = coHostTeleport.CFrame
					end
				end
			end
		end)
	end
end)

It is A LOT of string manipulating LOL!

1 Like

I have found the problems.

1: you need to have it check to see if they are in a team a few times, maybe like then they have died you can check again.

2: You spelt CFrame wrong:
What you did:

How you spell it:
CFrame

Hope this helped :slight_smile:

Ah, thank you. I will add these right now. :slight_smile:

1 Like

No problem, happy to help
If there are any more problems, I will be happy to help
:slight_smile:

Still didn’t work. :confused:

This text will be blurred

1 Like

I see the issue. As mentioned above there were some typos. But there is something else as well, the issue lies where you are comparing the strings to the commands in the if statements.

In the above if statement, you are trying to compare the input with the command. but you are taking the length of the string, not the string itself. Here is what the whole thing should be:

local prefix = ":"
local teleportCommand = "to"
local hostTeleport = game.Workspace.HostTeleport
local coHostTeleport = game.Workspace.CoHostTeleport

game:GetService("Players").PlayerAdded:Connect(function(Player)
	if (Player.TeamColor == BrickColor.new("Bright bluish green") or Player.TeamColor == BrickColor.new("Slime green")) then
		print("Initiated")
		Player.Chatted:Connect(function(Message)
			print("Chatted")
			local prefixLength = string.len(prefix)
			if (string.sub(Message, prefixLength + 1)) then
				print("Chatted big enough")
				local command = string.sub(Message, prefixLength + 1)
				local splitBySpaces = string.split(command, " ")
				print("Command: " .. splitBySpaces[1], splitBySpaces[2])
				if (splitBySpaces[1] == teleportCommand) and (splitBySpaces[2]) then
					if (splitBySpaces[2] == "host" and Player.TeamColor == BrickColor.new("Bright bluish green")) then
						local playerToTeleport = Player
						playerToTeleport.Character:FindFirstChild("HumanoidRootPart").CFrame = hostTeleport.CFrame
					elseif (splitBySpaces[2] == "cohost" and Player.TeamColor ==  BrickColor.new("Slime green")) then
						local playerToTeleport = Player
						playerToTeleport.Character:FindFirstChild("HumanoidRootPart").CFrame = coHostTeleport.CFrame
					end
				end
			end
		end)
	end
end)

Hope this helps!

2 Likes

did you swap to the team before the script checked?

You will need someway was check what team they are on.

Here is where the problem is:

game:GetService("Players").PlayerAdded:Connect(function(Player)
	if (Player.TeamColor == BrickColor.new("Bright bluish green") or Player.TeamColor == BrickColor.new("Slime green")) then

change that, to this:

game:GetService("Players").PlayerAdded:Connect(function(Player)
   Player.Chatted:Connect(function(Message)
       if (Player.TeamColor == BrickColor.new("Bright bluish green") or Player.TeamColor == BrickColor.new("Slime green")) then
1 Like

Ah, that is yet again a silly mistake. Thank you!

I know what your trying to say, but string.len() returns the string:

So this is not a problem, but it is useless.

It returns the length of the string. a number. He’s comparing a number to a string.

1 Like

Oh, why did I not read that when I was sending the image, nvm then, LOL

1 Like

I just wanted to repost this because it is one of the main problem I had with script.

Hope this helped. :slight_smile:

It was a combination of you two’s work, so therefore I’m not marking anyone as solution, it was a team effort. I will be adding solution to the title though! Thank you!

3 Likes
local hostTeleport = workspace.HostTeleport
local coHostTeleport = workspace.CoHostTeleport
local colors = {BrickColor.new("Bright bluish green"), BrickColor.new("Slime green")}

game.Players.PlayerAdded:Connect(function(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HRP = Character:WaitForChild("HumanoidRootPart")
	Player.Chatted:Connect(function(Msg)
		if string.match(Msg, "^:") then
			local Command = string.sub(Msg, ":")
			local SplitMsg = string.split(Command, " ")
			if (SplitMsg[1] == "to") and (SplitMsg[2]) then
				if (SplitMsg[2] == "host" and Player.TeamColor == colors[1]) then
					HRP.CFrame = hostTeleport.CFrame
				elseif (SplitMsg[2] == "cohost" and Player.TeamColor == colors[2]) then
					HRP.CFrame = coHostTeleport.CFrame
				end
			end
		end
	end)
end)