I want to create a system where if a player is a certain distance from a part, they would automatically teleport there. How could I go from this. I am thinking of using magnitude, but I am not really good with it.
You’re right on using Magnitude, you could just put it through a loop so that it’ll run infinitely & frequently check if the Player’s Distance is Greater, Less, or Equal to the Part
Magnitude is actually really easy to learn. Just subtract the positions of the the HumanoidRootPart and the part you want to check the distance of and add .Magnitude
to it.
I am thinking of grabbing the current HumanoidRootPart and every few seconds detecting if its in range. is this good?
I guess just use magnitude yea, also make sure to teleport the HumanoidRootPart and not the Torso, just saying.
You can use a localscript in StarterGui for the magnitude and if the player is near, you fire a remote event to the server.
Make sure to use the following in your LocalScript:
local player = game.Players.LocalPlayer
That would do just nicely
You could possibly implement something like this in a Server Script inside ServerScriptService
?
local PartToDetect = --The Part to detect yes
local Radius = --Radius if any
local Cooldown = 5
while true do
for _, Player in pairs(game.Players:GetPlayers()) do
local Character = Player.Character
if (Character.HumanoidRootPart.Position - PartToDetect.Position).Magnitude < Radius then
Character.HumanoidRootPart.CFrame = PartToDetect.CFrame
end
end
wait(Cooldown)
end
Or you could just go local-sided, although replication would act very strange across the server so I don’t know
Just a question, wouldn’t that teleport the player every 5 seconds if it’s in range?
I just put it for 5 seconds & the radius as examples, you could change however you wanna implement it but the OP didn’t exactly specify what “certain distance” we’re looking for
Oh ok then thanks. Is there a way you can send me the documented verison for magnitude so i can learn for myself. i tried looking but cant find it
Boop
thanks again. just testing in studio right now, it does not seem to actuall tp my player? im kinda of confused
You didn’t exactly specify what “distance” you want to check for? It depends on if you’re wanting to detect if the Part is close, far, or equal to a certain distance
Oh wait sorry. Just fixed it. I made it so if the distance of your position is greater than the radius I placed, then u would tp. I will probably change how long the cooldown is just for sanity lol
Yeah just be sure to configure around with the script and let me know how it goes
Alright then! Thanks for your help once again!