-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize communication between the server and clients
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
-- [[ NETWORK OPTIMIZATION SCRIPT FOR VANITY-ANTICHEAT ]] | ||
-- This script optimizes communication between server and client scripts | ||
|
||
local Players = game:GetService("Players") | ||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local HttpService = game:GetService("HttpService") | ||
local RunService = game:GetService("RunService") | ||
|
||
-- Create RemoteEvents for communication | ||
local remoteRequest = Instance.new("RemoteEvent") | ||
remoteRequest.Name = "RemoteRequest" | ||
remoteRequest.Parent = ReplicatedStorage | ||
|
||
local remoteResponse = Instance.new("RemoteEvent") | ||
remoteResponse.Name = "RemoteResponse" | ||
remoteResponse.Parent = ReplicatedStorage | ||
|
||
-- Function to measure latency | ||
local function measureLatency(player) | ||
local startTime = os.clock() | ||
|
||
-- Request latency measurement | ||
remoteRequest:FireClient(player, "ping") | ||
|
||
-- Wait for response | ||
local responseReceived = remoteResponse.OnServerEvent:Wait() | ||
|
||
local latency = os.clock() - startTime | ||
print("Latency for player " .. player.Name .. ": " .. latency .. " seconds") | ||
|
||
return latency | ||
end | ||
|
||
-- Function to optimize player data retrieval | ||
local function optimizePlayerData(player) | ||
local playerData = { | ||
UserId = player.UserId, | ||
Name = player.Name, | ||
CharacterPosition = player.Character and player.Character.HumanoidRootPart.Position or Vector3.new(0, 0, 0) | ||
} | ||
|
||
return playerData | ||
end | ||
|
||
-- Event for handling remote requests | ||
remoteRequest.OnServerEvent:Connect(function(player, requestType) | ||
if requestType == "ping" then | ||
remoteResponse:FireClient(player, "pong") | ||
elseif requestType == "getPlayerData" then | ||
local playerData = optimizePlayerData(player) | ||
remoteResponse:FireClient(player, playerData) | ||
end | ||
end) | ||
|
||
-- Monitor player added | ||
Players.PlayerAdded:Connect(function(player) | ||
-- Measure latency on player join | ||
measureLatency(player) | ||
|
||
-- Additional logic to monitor or optimize data retrieval as needed | ||
end) | ||
|
||
-- Run service to periodically optimize player connections | ||
RunService.Heartbeat:Connect(function() | ||
for _, player in ipairs(Players:GetPlayers()) do | ||
-- Logic to continuously check and optimize player data or connections | ||
local latency = measureLatency(player) | ||
if latency > 0.1 then -- Threshold for optimization | ||
print("Player " .. player.Name .. " has high latency: " .. latency .. " seconds. Consider optimizing.") | ||
end | ||
end | ||
end) | ||
|
||
print("Network optimization script loaded for VANITY-ANTICHEAT.") |