Help With Push Tool

how can i make my code do the same as in the video. i am working on that tool 2 days and can’t make it do the same as i want.

what i want:
https://gyazo.com/50b24f07c08506c29843eec537416eee

my push tool:
https://gyazo.com/d94cb95e6b2812e0e5dccd86a493bb99

my local script:

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

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

--//Tables
local Connections = {}

--//Functions
Tool.Activated:Connect(function()
	if debounce then
		return
	end

	debounce = true

	local humanoid = game.Players.LocalPlayer.Character.Humanoid
	local Anim = script.Parent:FindFirstChild("Animation")

	--local ThrowChairAnim = humanoid:LoadAnimation(Anim)
	local coolAnimation = Tool.Parent.Humanoid.Animator:LoadAnimation(Anim)
	coolAnimation:Play()
	wait(0.9)
	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)

my server script:

local Players = game:GetService("Players")

local pushPower = 500

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)

image

Change your server script to this:

local Players = game:GetService("Players")

local pushPower = 500
local pushHeight = 500

script.Parent.Push.OnServerEvent:Connect(function(player, otherCharacter)
	if not otherCharacter or typeof(otherCharacter) ~= "Instance" or player.Character == otherCharacter 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
	
	local playerCFrame = player.Character.HumanoidRootPart.CFrame
	humanoidRootPart:ApplyImpulse(playerCFrame.LookVector * pushPower + playerCFrame.UpVector * pushHeight)

	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)

And your local script to this:

--//Services
local Players = game:GetService("Players")

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

--//Controls
local pushDuration = 1
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(Animation)
	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)
2 Likes