local p=game.Players.LocalPlayer local char=p.Character local root=char:WaitForChild('HumanoidRootPart') local mouse=p:GetMouse() function tele() char.Humanoid:MoveTo(mouse.Hit.p) end mouse.Button1Down:Connect(function() tele() end)
the script above would allow the player to teleport anywhere on the map without limitations. is there any way for it to not activate if the distance is farther than 100 studs?
Check the distance with an if statement. You also have other important problems.
--consider using variable "player" over "p" local p=game.Players.LocalPlayer local char=p.Character or p.CharacterAdded:wait() --incase char is not loaded local root=char:WaitForChild('HumanoidRootPart') local mouse=p:GetMouse() function tele() --define vectors local origin = root.CFrame.p local target = mouse.Hit.p + Vector3.new(0,3,0) --elevate root if (target-origin).magnitude < 100 then --distance between --MoveTo should be used on character, not humanoid char:MoveTo(target) end end --since tele is a basic function, you can simply pass it in mouse.Button1Down:Connect(tele)
If you don't want to prohibit the teleport, but minimize it, you can shorten the position vector.
function tele() local origin = root.CFrame.p local target = mouse.Hit.p + Vector3.new(0,3,0) local diff = target-origin if diff.magnitude > 100 then --same direction (unit) but length 100 target = origin + diff.unit * 100 end char:MoveTo(target) end
Edit: It's best to offset the mouse height.