-
What do you want to achieve?
So I’m trying to do a script that causes the baseplate to shake and unanchor parts in workspace. When those parts hit a player, they deal damage. -
What is the issue?
The issue is, theres a lot of parts in one building alone, and i wouldn’t have a script inside each part detecting a .Touched event to deal damage, right? So I was thinking on making a script inside the character, but I would need some guidance.
Be cautious with how you approach this, as unanchoring a ton of Parts
in the workspace can cause major lag. The server has to calculate the position each part is going to be in according to the physical properties, and then has to replicate that information to every client in the server, every frame.
Even with simple maps on Natural Disaster Survival by stickmasterluke, there can be some lag with all of the parts moving around. If you decide to stick with this approach, try and keep your part count to a minimum.
As for how you could calculate the damage the part should deal, you could try keeping a short-term storage for each part’s position of the last S
seconds. When a part touches a player, (through a .Touched
event on the Player’s Character
parts), you can reference the history of where that part has been as a function of time to determine it’s velocity. This velocity can be directly proportional to the damage dealt to the player, multiplied by some dampening or scaling factor if necessary.
If I find some free time I will look into some different testing environments to see which is more suitable, or if using .Magnitude
checks would be better than .Touched
for this case. .Touched
has a history of being unreliable.