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

Adding a range on a GetService script?

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

3 comments

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?

0

You didn't really specify what the purpose of the part is and what the "range" does..

0

yes thats what i meant

1 answer

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 

1 comment

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

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