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

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

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?

1 comment

0

You could use magnitude locally to check if the player is within combat distance

1 answer

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

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