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

How do I teleport a part in the workspace/replicatedstorage and teleport it to the localplayer?

If you're familiar with Magic Training or Harry Potter, you'll be familiar with the protego spell. We're making a game and when you press q it should fire a remoteevent which sets off a function that teleports a part (the protego spell) to the localplayer, and makes it follow the player for a duration of 0.75 seconds. The only issue is I'm not sure how to make it teleport to you and because of that I don't know how to make it follow. Please help?

1 answer

✓ Accepted answer

To "teleport" parts, or simply move them around, you would use CFrames. So when you call the function, it would start a loop that would continuously change the Protego part's CFrame to the player's HumanoidRootPart's CFrame.

But a more specific and practical way to do this would be to have a function that clones the Protego part from server storage or wherever you keep it into the workspace and then another function that checks if the part has spawned (set a boolean equal to true if the part exists, false if it doesn't) and updates it's position with CFrames.

In the OnServerInvoke event you call the part clone function, and set the partExists boolean to true, then you wait(0.75), then set partExists boolean to false, then destroy the protego part.

In a RunService.Heartbeat event, you check if partExists, then update the part's CFrame. Once the part gets destroyed, this won't run anymore, but it will still check for a new part if protego is called again because it runs every heartbeat.

5 comments

0

This causes a lot of performance issues if you have a bunch of players. Not very efficient. I would either weld it to the player or use BodyPosition but use collision groups to avoid a lot of physics calculations.

0

https://devforum.roblox.com/t/how-to-make-a-part-follow-you/357913/6 Here's also something that assists with this. Apparently there has been something called "AlignPosition" that you can use for this as well. There's also 'AlignOrientation' apparently. Roblox is pretty helpful for making all these tools so we should use them all.

0

This does not cause ANY performance issues. Heartbeat runs AFTER physics simulations, you might be confusing this with renderstepped which runs BEFORE rendering. That is what causes performance issues.

0

Another reason why you would want to use this is because it only exists for a fraction of a second, it wouldn't make sense to create a weld for a part that exists for less than a second and then destroy it, and also this is exactly how bullets are handled in FPS games, the bullets are created, then each heartbeat, the ray/cframe is updated and the bullet follows that path.

0

Thanks for the help guys.

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