Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i add a range to my teleport?

its local script

local Player = game:GetService("Players").LocalPlayer

local rp = game:GetService("ReplicatedStorage")
local Teleport = rp:WaitForChild("Stand1Remotes"):WaitForChild("Teleport")

local debounce = false
local cooldown = 5 
local UIS = game:GetService("UserInputService")

local debounce = false
local Player = game:GetService'Players'.LocalPlayer

local UIS = game:GetService('UserInputService')
local Mouse = Player:GetMouse()

local Player = game:GetService'Players'.LocalPlayer
local Mouse = Player:GetMouse()
local Cooldown = false


UIS.InputBegan:Connect(function(key, IsTyping)
    if IsTyping or Cooldown then return end
  if key.KeyCode == Enum.KeyCode.H then
   Cooldown = true
	       
	 local Character = Player.Character or Player.CharacterAdded:Wait()
    local Root = Character:WaitForChild('HumanoidRootPart')
    Root.CFrame = Mouse.Hit
	   
		Teleport:FireServer()
			 wait(3)
		  Cooldown = false
	  end
end)

3 comments

0

Just get the magnitude of the distance between the rootpart and the mouse.hit and see if it's beyond a certain value (i.e 50 studs); then end the function if it is.

0

By magnitude of the distance I mean (Mouse.Hit - RootPart.CFrame).Magnitude > 50.

0

im still like know 3.5/10 in scripting so can you do the script for a fellow learner

1 answer

Hello sir, here to a script to teleport you from one brick to another.............

--[[
You will also need to have some setup before putting this script in your place. You can do it however you would like, but with MY setup I have 2 parts in my workspace. One is called "Part1" and the other is called "Part2" and my script will work if you setup like this.
]]
local part1 = workspace:WaitForChild("Part1")
local part2 = workspace:WaitForChild("Part2")

local debounceTable = {}
--[[
debounceTable is used to keep track of the player that
just teleported, and makes sure they're able to get off
before being teleported again. (So they don't get telep
-orted back and forth and can't get off)
]]

--This detects if the touching object is a player for part1
part1.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and table.find(debounceTable,hit.Parent) == nil then
        table.insert(debounceTable,hit.Parent)
        hit.Parent:MoveTo(part2.Position)
        wait(2)
        table.remove(debounceTable,table.find(debounceTable,hit.Parent))
    end
end)
--This detects if the touching object is a player for part2
part2.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and table.find(debounceTable,hit.Parent) == nil then
        table.insert(debounceTable,hit.Parent)
        hit.Parent:MoveTo(part1.Position)
        wait(2)
        table.remove(debounceTable,table.find(debounceTable,hit.Parent))
    end
end)

4 comments

0

you got the question wrong im asking for a range so that i cant tp too far away thanks anyway

0

Sorry sir, I tryed...............................

0

Do you want to teleport to a random place within a range?

0

i need to teleport to my mouse when H is clicked, it works but i need range so i dont just go 1000000000studs away

This discussion is preserved as it was. New answers, comments, and votes are closed.