Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Magnitude or Radius, teleportation help?

Asked by 5 years ago

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!

0
Have you tried my other method yet? I know it's not exactly what you wanted, but it should work. SteamG00B 1633 — 5y
0
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. SteamG00B 1633 — 5y
0
sorry, when I copied your script over, I forgot to remove the .magnitude off of the end of your lines SteamG00B 1633 — 5y

1 answer

Log in to vote
1
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago
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)

0
Just tried this and i'm getting the following error: https://gyazo.com/47df28caac8142a8b6b98ff10e6399f6 xXTouchOfFrostXx 125 — 5y
0
Legend! It works, thank you so much! xXTouchOfFrostXx 125 — 5y
Ad

Answer this question