Im making a combat system in which once the player gets close enough to an enemy, the client then handles the battle. How can I tell the client that the player is engaging in a fight in the most efficient way possible?
You'll probably want to check on the client, how far they are from their enemy, and if they are close enough, it engages the system. You could also use remote events and function if you want the server to know about it. To check magnitude:
local p1, p2 = workspace.p1, workspace.p2 local magnitude = (p1.Position - p2.Position).magnitude --the order doesn't matter
If you have a table of all engagable enemies then:
local enemies = {enemy1, enemy2, etc...} local p = game.Players.LocalPlayer local engage = 15 local n = 0 for i,v in pairs (enemies) do if (p.Character.Torso.Position - enemies[i]).magnitude < engage then n = i end end if n ~= 0 then enemy = enemies[n] --where the enemy is engaged, tell the client here end
Typing this on phone so sorry if I made any mistakes or didnt explain anything clearly enough