i'm Scripting a Filtering Enabled Teleport Tool, you may have seen in some games wich contain a Teleport Tool, right? the problem is that in some of those games you can teleport to.. the void.. but, with my Teleport tool you can only teleport within a range of 200 Studs, heres my code:
Local Script:
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait(.1)
local Tool = script.Parent
local Mouse = Player:GetMouse()
local CanTeleport = true
Tool.Activated:Connect(function()
if CanTeleport then
CanTeleport = false
Tool.TeleportEvent:FireServer(Mouse.Hit.p, Mouse.Target,
Character:FindFirstChild("HumanoidRootPart"))
wait(1)
CanTeleport = true
end
end)
Server Script:
local Tool = script.Parent
local Range = 200
function CanTeleport(Position, TargetPart, RootPart)
if Position ~= nil and TargetPart ~= nil and RootPart ~= nil then
if Position.X < RootPart.Position.X + Range and Position.Y < RootPart.Position.Y + Range and Position.Z < RootPart.Position.Z + Range then
if Position.X > RootPart.Position.X - Range and Position.Y > RootPart.Position.Y - Range and Position.Z > RootPart.Position.Z - Range then
return true
end
end
end
end
Tool.TeleportEvent.OnServerEvent:Connect(function(Client, MousePosition, MouseTarget, RootPart)
if CanTeleport(MousePosition, MouseTarget, RootPart) then
print('teleported')
end
end)
You see CanTeleport() function is very complex, i want to know if i can use an alternative way so i don't have to make complex calculus, i got dizzy while trying to make those calculus @-@

2 comments
now my code look much Cleaner :)
Glad I could help :)