Don't work well the SetNetworkOwner

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)

make the push all client (like add code on server that will fire the enemyClient and add the code on client that will receive the push), if a player wanna cheat he can still mess around with movement system

i solved the problem, i only changed two things and it worked, this is the server script that solved it:


	hrp:SetNetworkOwner(player) -- *to hrp:SetNetworkOwner(nil)*

	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) -- *to hrp:SetNetworkOwner(targetPlayer)*
		end
	end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.