Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I contact client in the most efficient way possible from server?

Asked by 6 years ago

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?

0
You could use magnitude locally to check if the player is within combat distance abnotaddable 920 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

Ad

Answer this question