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

How do i Detect when another Player Touches the Player Teleporting?

Asked by 4 years ago
Edited 4 years ago

Hey So I've been Attempting to Make a teleport script, (tool)

local cooldown = false
repeat wait() until game.Players.LocalPlayer.Character

local plr = game.Players.LocalPlayer
local MyBody = plr.Character
local mouse = plr:GetMouse()

script.Parent.Activated:Connect(function()
  if not cooldown then
    cooldown = true
    local hit = mouse.Hit
    wait(1)
    MyBody:MoveTo(hit.p)
    wait(1)
    cooldown = false
  end
end)

I need it So when a Player Touches another Player, They Get Teleported wih the Teleporting Player, Thanks

1 answer

Log in to vote
0
Answered by
sheepposu 561 Moderation Voter
4 years ago

Make two events. A touched event and touch ended event. Make a list in the beginning of the script to store the players currently touching the current player. Under the touched function, check to make sure that a player is touching them, and add their name to the list. Do the opposite for the touchended, if it's a player, remove their name from the list. If you were to set this event to all the body parts it may be hard to tell when they stop touching one part of the character but are still touching another part. So it may be easier to just set the events on only the upper torso. Once the events are established then when it teleports, have it cycle through each player in the list and teleport them as well. Also you may want to execute the move functions in a server script through a remote event as doing it on the client will cause the position of the player only to update on the client side. Everyone else in the server won't see you teleport. Hope this helps.

Ad

Answer this question