I'm trying to make a script that allows the user to teleport with multiple people if they are within a certain magnitude or radius. However, i've tried both methods but can't seem to teleport both the user and the people around the user.
Any ideas?
Local Script
Debounce = false
local mouse = script.Parent.Parent:GetMouse()
game:GetService('UserInputService').InputBegan:connect(function(input, gameprossed)
if input.KeyCode == Enum.KeyCode.T and Debounce == false then
Debounce = true
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage:WaitForChild("Apparate")
Teleport:FireServer(mouse.hit.p)
wait(2)
Debounce = false
end
end)
** Server Script 1 - Magnitude **
game.ReplicatedStorage.Apparate.OnServerEvent:Connect(function(player, MouseHit)
local radius = 5
local children = game.Players:GetChildren()
for i, child in pairs(children) do
if (child.Character.Head.Position - player.Character.Head.Position).magnitude <= radius then
child.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit)
player.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit)
end
end
end)
**Server script 2 - Radius **
game.ReplicatedStorage.Apparate.OnServerEvent:Connect(function(player, MouseHit)
local radius = 5
local children = game.Players:GetChildren()
for i, child in ipairs(children) do
if child:DistanceFromCharacter(Vector3.new(player.Character.HumanoidRootPart.CFrame) < radius then
child.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit)
player.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit)
end
end
end)
I have tried both methods of Radius and Magnitude, (obviously at different times) and I can't seem to get them to work...
Any ideas?
Thank you in advance. + Merry Christmas!

3 comments
Have you tried my other method yet? I know it's not exactly what you wanted, but it should work.
Oh I know why this might not work, if a player is jumping, but also 5 studs away, then their head will be more than 5 studs away.
sorry, when I copied your script over, I forgot to remove the .magnitude off of the end of your lines