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!
game.ReplicatedStorage.Apparate.OnServerEvent:Connect(function(player, MouseHit) local radius = 5 local children = game.Players:GetChildren() for i, child in pairs(children) do if math.abs(child.Character.Head.Position.X - player.Character.Head.Position.X)<= radius or math.abs(child.Character.Head.Position.Z - player.Character.Head.Position.Z)<= radius then child.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit) player.Character.HumanoidRootPart.CFrame = CFrame.new(MouseHit) end end end)
So I changed it so it would only detect the position on the x and z axis, so that even if a player jumps, it should teleport them.
also pretty sure hit should be capitalized, so that one line in the local script should be
Teleport:FireServer(mouse.Hit.p)