Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
optimize communication between the server and clients
  • Loading branch information
luvmad authored Nov 1, 2024
1 parent ef57e1c commit 77c8d30
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions VANITY-ANTICHEAT-NETWORK-OPTIMISER.lua
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.")

0 comments on commit 77c8d30

Please sign in to comment.