Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Push = ReplicatedStorage:WaitForChild("Push")
local FUERZA = 100
local IMPULSE_TIME = 0.5
local COOLDOWN = 0.5
local lastPushTimes = {}
Push.OnServerEvent:Connect(function(player, targetPlayer, direccion)
if typeof(direccion) ~= "Vector3" then return end
if not targetPlayer or not targetPlayer.Character then return end
local hrp = targetPlayer.Character:FindFirstChild("HumanoidRootPart")
if not hrp then return end
local lastPush = lastPushTimes[targetPlayer] or 0
if os.clock() - lastPush < COOLDOWN then return end
lastPushTimes[targetPlayer] = os.clock()
local pushDir = Vector3.new(direccion.X, 0, direccion.Z)
if pushDir.Magnitude == 0 then return end
pushDir = pushDir.Unit
hrp:SetNetworkOwner(player)
local rawImpulse = pushDir * FUERZA * hrp.AssemblyMass
local maxImpulse = 66 * hrp.AssemblyMass
if rawImpulse.Magnitude > maxImpulse then
rawImpulse = rawImpulse.Unit * maxImpulse
end
print(rawImpulse.Magnitude)
hrp:ApplyImpulse(rawImpulse)
task.delay(IMPULSE_TIME, function()
if hrp then
hrp:SetNetworkOwner(nil)
end
end)
end)
Client:
local PUSH_RANGE = 2.8
local COOLDOWN = 0.5
local IMPULSE_FACTOR = 50
local lastPushTimes = {}
RunService.RenderStepped:Connect(function()
local vel = hrp.AssemblyLinearVelocity
for _, enemy in ipairs(Players:GetPlayers()) do
if enemy ~= plr then
local char = enemy.Character
if char and enemy:FindFirstChild("you_turn") and not enemy.you_turn.Value then
local enemyHRP = char:FindFirstChild("HumanoidRootPart")
if enemyHRP then
local offset = enemyHRP.Position - hrp.Position
local distance = offset.Magnitude
if distance > 0 and distance <= PUSH_RANGE then
local lastPush = lastPushTimes[enemy] or 0
if os.clock() - lastPush >= COOLDOWN then
local dir = Vector3.new(offset.X, 0, offset.Z).Unit
local impulse = dir * vel.Magnitude * IMPULSE_FACTOR
Push:FireServer(enemy, impulse)
lastPushTimes[enemy] = os.clock()
end
end
end
end
end
end
end)