Making a Teleport Script

Hello Developers,

I am currently making some powers for my game, and the one i currently need to do is a Teleportation Script.

I have thought of two ways of doing it.

Way One

Make it so the player teleports x studs in front of their actual position.

I have a problem with this idea, because the player would be able to go through walls and that’s not what i want, so that’s the reason i think Way two is better.

Way Two

The second way i wanted to make it, was that the player teleports to where their mouse is pointing, that way they can’t teleport where they can not see.

I think a tool would suit best for this.

Needs

I have some things to keep in mind while doing this, mostly one thing.

It must be toggable, meaning the player can use it once and it will turn off, that can be used in a UI or a Tool.

I would greatly appreciate if someone could tell me how to make that, please do not tell me what i need to do and yet how to do it.

Also it’s very late in my time zone so i’ll probably only be reading answers tomorrow :stuck_out_tongue:

I know this can be hard but i am open for easier suggestions and all help.

Thanks! :slightly_smiling_face:

2 Likes

Use Mouse.Target, Raycasting and CFrame. It would have to be semi client sided but in general you should be able to protect it from exploiters.

I’m not very concerned with exploiters, as not everyone in the game will have access to these powers, so just the script itself was gonna be good, thanks for the help.

For the teleportation, I recommend you look up “CFrame”. In short, they have a position and rotation stored in them.
For method one, you could launch a raycast in front of the player to see if it hits any walls, and then change the teleport destination to whatever position the raycast hit.
For method two, use :GetMouse() and mouse.hit, then just set the CFrame to whatever position hit.
There are also dozens of tutorials about this on youtube or other places on the devforum.

3 Likes

Thanks! I did do a little search before making the thread, but it’s easier to have people helping me live, and helping me if i have some problem, instead of just watching something that’s been done months ago.

Thanks for the help tho!

If you want to do it with a tool, simply create a tool, set its RequiresHandle to false.

When the player activates the tool it’ll run a code that teleports them to another position using CFrame then after that just simply :Destroy() the tool.

1 Like