I'm trying to create a script which allows the user to press "T" on their keyboard and teleport to wherever their mouse is. However, I've managed to cover that part but now i'm trying to use radius to check for any players within 5 studs of the user pressing "T" and if they are, teleport them along with the user to the location of the mouse position. It's my first time using radius detection and I can't seem to make it work... Anyone able to help?
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
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)
Thank you. :)

2 comments
If you're wondering why I thought of such a weird solution, then let me tell you that my solution for getting user input to work with a plane was to put the entire plane model inside the character.
Well