✓ 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:
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
Hello. Thanks for the reply. However, this has not fixed my issue.
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?
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.
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)statementDetects the maginute higher than 140 but it is not setting the CFrame of the RootPart
yup i think i got it, i edited my answer
That worked. Thanks!