Help With Push Tool

Hello, i want to make push tool when the handle hits human then it will push him
my script don’t work for some reason if someone can help me and explain to me i will appreciate a lot

server script:

script.Parent.Push.OnServerEvent:Connect(function(player)

	local pushRoot = player:FindFirstChild("HumanoidRootPart")


	local pushF = Instance.new("BodyVelocity",pushRoot)

		pushF.Name = "PushForce"
		pushF.MaxForce = Vector3.new(1000000, 1000000, 1000000)
		pushF.Velocity = 110


		wait(0.3) 

		pushF:Destroy()
end)

local script:

script.Parent.Handle.Touched:Connect(function(hit)

script.Parent.Push:FireServer(hit.Parent)

end)
  1. The first argument for .OnServerEvent is the player who fired it, not your first argument
  2. BodyVelocity.Velocity takes in a Vector3

Also, scripts don’t run in ReplicatedStorage.

New server code:

local pushPower = 100000

script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
	if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
		return
	end
	
	local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")
	
	if not humanoidRootPart then
		return
	end
	
	humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
end)

its work but now i have other problem, i want it to push him when he touch it and the tool is activated
like when i click the mouse and the player touch it, it will push him

Change your client script to this:

--//Variables
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Push = Tool:WaitForChild("Push")

--//Controls
local pushDuration = 3
local debounce = false

--//Tables
local Connections = {}

--//Functions
Tool.Activated:Connect(function()
	if debounce then
		return
	end
	
	debounce = true
	
	Connections.Pushed = Handle.Touched:Connect(function(hit)
		Push:FireServer(hit.Parent)
	end)
	
	task.wait(pushDuration)
	
	local connection = Connections.Pushed
	
	if connection then
		connection:Disconnect()
		Connections.Pushed = nil
	end
	
	task.wait(1)
	debounce = false
end)

This will activate the push for 3 seconds when the player clicks, and then disable it after.

its not working, i tried to print some things inside the code and its not printing anything.

image
this part not working

image.

did you touch a player after you clicked?

ok, now its printing everything i do but its not pushing the player

the problem is not really wierd. i can’t push real players only NPC’S
its just not work on real players only npcs

Change your server code to this:

local Players = game:GetService("Players")

local pushPower = 100000

script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
	if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
		return
	end

	local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")

	if not humanoidRootPart then
		return
	end
		
	for i, descendant in ipairs(otherCharacter:GetDescendants()) do
		if not descendant:IsA("BasePart") then
			continue
		end
		
		descendant:SetNetworkOwner(nil)
	end

	humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
		
	local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
	
	if otherPlayer then
		task.wait(2)

		for i, descendant in ipairs(otherCharacter:GetDescendants()) do
			if not descendant:IsA("BasePart") then
				continue
			end

			descendant:SetNetworkOwner(otherPlayer)
		end
	end
end)

omg thats work thank you soo much,
i have last question please where in the local script i can put animation for the tool
in which line?

You can do this: (client code)

--//Variables
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Push = Tool:WaitForChild("Push")

--//Controls
local pushDuration = 3
local debounce = false

--//Tables
local Connections = {}

--//Functions
Tool.Activated:Connect(function()
	if debounce then
		return
	end
	
	debounce = true
	
	local coolAnimation = Tool.Parent.Humanoid.Animator:LoadAnimation(workspace.MyCoolAnimation)
	coolAnimation:Play()

	Connections.Pushed = Handle.Touched:Connect(function(hit)
		Push:FireServer(hit.Parent)
	end)

	task.wait(pushDuration)

	local connection = Connections.Pushed

	if connection then
		connection:Disconnect()
		Connections.Pushed = nil
	end

	task.wait(1)
	debounce = false
end)

i have error in that part line 20

image

Oops, new server code:

local Players = game:GetService("Players")

local pushPower = 100000

script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
	if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
		return
	end

	local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")

	if not humanoidRootPart then
		return
	end
		
	for i, descendant in ipairs(otherCharacter:GetDescendants()) do
		if not descendant:IsA("BasePart") or descendant.Anchored then
			continue
		end
		
		descendant:SetNetworkOwner(nil)
	end

	humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)
		
	local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
	
	if otherPlayer then
		task.wait(2)

		for i, descendant in ipairs(otherCharacter:GetDescendants()) do
			if not descendant:IsA("BasePart") or descendant.Anchored then
				continue
			end

			descendant:SetNetworkOwner(otherPlayer)
		end
	end
end)

in the server script i don’t know where to place my ragdoll could you help me please.

for index, joint in pairs(otherCharacter:GetDescendants()) do
	if joint:IsA("Motor6D") then
		local socket = Instance.new("BallSocketConstraint")
		local a1 = Instance.new("Attachment")
		local a2 = Instance.new("Attachment")
		a1.Parent = joint.Part0
		a2.Parent = joint.Part1
		socket.Parent = joint.Parent
		socket.Attachment0 = a1
		socket.Attachment1 = a2
		a1.CFrame = joint.C0
		a2.CFrame = joint.C1
		socket.LimitsEnabled = true
		socket.TwistLimitsEnabled = true
		joint:Destroy()
	end
end

New server code:

local Players = game:GetService("Players")

local pushPower = 100000

script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
	if not otherCharacter or typeof(otherCharacter) ~= "Instance" then
		return
	end

	local humanoidRootPart = otherCharacter:FindFirstChild("HumanoidRootPart")

	if not humanoidRootPart then
		return
	end

	for i, descendant in ipairs(otherCharacter:GetDescendants()) do
		if not descendant:IsA("BasePart") or descendant.Anchored then
			continue
		end

		descendant:SetNetworkOwner(nil)
	end
	
	for index, joint in pairs(otherCharacter:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
		end
	end

	humanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector * pushPower)

	local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)

	if otherPlayer then
		task.wait(2)

		for i, descendant in ipairs(otherCharacter:GetDescendants()) do
			if not descendant:IsA("BasePart") or descendant.Anchored then
				continue
			end

			descendant:SetNetworkOwner(otherPlayer)
		end
	end
end)