Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my Teleportation command not working as supposed to?

Asked by 10 years ago

I have checked, and rechecked what could I have done wrong, but I do not see any errors, I have added a few prints to see which ones would print, and Chk1 was the only one that would print, it did not print Chk2 nor Chk3 aswell, also if you typed '_tp me' the script would break for some reason, I do not know how to fix this command anymore, I have already conducted numerous tests to get it to work, here is the script;

if msg:lower():sub(1,3+#Prefix) == Prefix.."tp " then
local chk1 = msg:lower():sub(4+#Prefix):find(" ")
local plrz = GetPlr(plr,msg:lower():sub(4+#Prefix,chk1-1-#Prefix))
local plrz2 = GetPlr(plr,msg:lower():sub(chk1+1+#Prefix))
print("Chk1") --It will only print this
if chk1 then chk1 = chk1  + 3+#Prefix end --I've tried this to keep from getting the Error, but it still comes up after typing '_tp me', and breaking the script for some reason
for i,v in pairs(plrz) do --Sadly when it gets here, it appears to stop
print("Chk2") --It will not print this
coroutine.wrap(function()
for i2,v2 in pairs(plrz2) do
print("Chk3") --Nor this
if v and v2 and v.Character and v2.Character then
v.Character:MoveTo(v2.Character.Torso.CFrame:GetModelCFrame().p+Vector3.new(0,1,0))
end
end
end)()
end
end
1
could you tab out your code? VariadicFunction 335 — 10y
0
Yes, do tab you code please. Perci1 4988 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

I would personally recommend the usage of String Patterns.

if msg:lower():match("^"..Prefix.."tp %w+ %w+") then
local Plr1Name = msg:lower():match("^"..Prefix.."tp (%w+) %w+") -- This is Player1's name
local Plr2Name = msg:lower():match("^"..Prefix.."tp %w+ (%w+)") -- This is Player2's name
-- Do your GetPlayer stuff, Plr1Name is player1 and Plr2Name is Player2.
end

If you would like to see how it works easily, run this in the Command Bar and check the Output:

local Prefix = "_"
local msg = "_tp p1 p6345"

local Plr1Name = msg:lower():match("^"..Prefix.."tp (%w+) %w+")
local Plr2Name = msg:lower():match("^"..Prefix.."tp %w+ (%w+)")

print(Plr1Name, Plr2Name)
Ad

Answer this question