Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleport back script not teleporting the player back?

Hello.

I am currently trying to make a TP back script, and it detection works, however it does not TP the player back. I am unsure what the cause of this is, and would like some help.

My script:


function CheckTeleport()
	if HumanoidRootPart == nil then return Kick() end
	
	local PositionFirst = HumanoidRootPart.Position
	
	delay(1, function()
		local PositionSecond = HumanoidRootPart.Position
		
		if (PositionSecond - PositionFirst).Magnitude >= 140 then return HumanoidRootPart.CFrame == CFrame.new(PositionFirst.Position.X, PositionFirst.Position.Y, PositionFirst.Position.X) end
	end)
end

Thanks

1 answer

✓ Accepted answer

== returns a boolean

The == means equal in lua and it returns boolean, true or false based off of the condition, for example:

if (5 == 5) then warn('5 is 5') end

if (5 == 4) then warn('5 is not 4') end

if (true) then warn('true is true') end

if (false) then warn('false no no no') end

if (nil) then warn('nil is not valid') end

> Output:
--> 5 is 5
--> true is true

it is not setting CFrame of the HumanoidRootPart to the CFrame but returns if the part's CFrame is CFrame.new(PositionFirst.Position.X.... To fix that all you need to do is remove the == and return.

delay(1, function()
	local PositionSecond = HumanoidRootPart.Position

 	if (PositionSecond - PositionFirst).Magnitude >= 140 then
		HumanoidRootPart.CFrame = CFrame.new(PositionFirst.Position.X, PositionFirst.Position.Y, PositionFirst.Position.X)
	end
end)

Did you use return to return new character's CFrame? If so then just return his new CFrame like this

	if (PositionSecond - PositionFirst).Magnitude >= 140 then
		HumanoidRootPart.CFrame = CFrame.new(PositionFirst.Position.X, PositionFirst.Position.Y, PositionFirst.Position.X)
		return HumanoidRootPart.CFrame
	end
end)

Edit

Okay i see now, both of variables FirstPosition and SecondPosition are Vector3 values... not a problem, you check the magnitude and everything works well but the problem comes when you are setting HumanoidRootPart's CFrame to Vector3, doing CFrame with 3 arguments is same as setting it's position to Vector3 which won't move the Character, all you have to do is change FirstPosition and SecondPosition to HumanoidRootPart.CFrame and then setting his CFrame to one of it's positions. To get the Magnitude you would use CFrame.Position which returns Position as a Vector3.

local PositionFirst = HumanoidRootPart.CFrame

delay(1, function()
	local PositionSecond = HumanoidRootPart.CFrame

 	if (PositionSecond.Position - PositionFirst.Position).Magnitude >= 140 then
		HumanoidRootPart.CFrame = PositionFirst
	end
end)

7 comments

0

Hello. Thanks for the reply. However, this has not fixed my issue.

0

one thing that comes into my mind when i look at your question is that you define [FirstPosition] second before [SecondPosition], can user move 140 studs far in a second? Or is there something i don't know about, you said the detection works, what exactly did you mean by that?

0

It's supposed to be a script that detect teleportation exploits, if detected, instead of a kick I thought it would be a better idea to teleport them back instead.

0

so it detects that the magnitude was higher than 140 but is not setting CFrame of the RootPart right? Or it is not even passing the if (Magnitude >= 140) statement

0

Detects the maginute higher than 140 but it is not setting the CFrame of the RootPart

0

yup i think i got it, i edited my answer

0

That worked. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.