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

Adding a range on a GetService script?

Asked by 5 years ago

I have a script which i can only get to work in a local script (which is ok) in the starter pack(which makes it global) but i want the script its self to be in a block with a range on it.

function teleport()
    local char = game:GetService("Players").LocalPlayer.Character
    char.HumanoidRootPart.CFrame = CFrame.new(-185.8, 357.3, -569.6)

end

game:GetService("ContextActionService"):BindAction(
    "Teleport",
    teleport,
    false,
    Enum.KeyCode.E
)

dose any one know anything i need to add or change on this script

THX :D

0
I assume you want the block to teleport the player to the specified coords if you press E and are in a certain range of the part? T0XN 276 — 5y
0
You didn't really specify what the purpose of the part is and what the "range" does.. T0XN 276 — 5y
0
yes thats what i meant snakieandy -1 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Aye, you used the code I helped you with.

To get the range, find the magnitude of the part:

local dist = (char.HumanoidRootPart.Position - part.Position).magnitude

if dist <= 20 then -- make 20 bigger if you want more range, smaller for less.
    --do your code  
end 
0
srry cant seam to get it to work do i keep this in the starter pack or put it in the part its self snakieandy -1 — 5y
Ad

Answer this question