Help Needed with Pushing System in Goat Simulator Game

Hello Developers,

I am currently making a goat simulator game and I am stuck with the pushing system.

  1. What do you want to achieve? I want to create a feature where my goat can push both NPCs and players in the game.

  2. What is the issue? The script I have written fully works but it only pushes NPCs and not players. Below is my code for reference:

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local isAttacking = false
local debounce = false
local hitted = false

local function getPlayerRotation()
	local char = player.Character

	if char then
		return char.Head.CFrame.LookVector.Z, char.Head.CFrame.LookVector.X
	end
end

local function radiansToDegrees(radians)
	return radians * (180 / math.pi)
end

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if debounce then
			return
		end
		
		local attribute = player:GetAttribute("CanAttack")
		
		if attribute == true then
			return
		end

		debounce = true

		player.PlayerGui:WaitForChild("AttackGui").TextButton.Frame.Size = UDim2.new(1, 0, 1, 0)
		local tweenInfo = TweenInfo.new(1.4, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
		local sizeGoal = UDim2.new(0, 0, 1, 0)
		local anim = TS:Create(player.PlayerGui:WaitForChild("AttackGui").TextButton.Frame, tweenInfo, {Size = sizeGoal})
		anim:Play()

		local character = script.Parent
		local humanoid = character:WaitForChild("Humanoid")
		local attackAnim = script:WaitForChild("Attack")
		local attackAnimTrack = humanoid.Animator:LoadAnimation(attackAnim)
		attackAnimTrack:Play()

		delay(0.3, function()
			print("attacking...")
			isAttacking = true

			player.Character.HitHitbox.Touched:Connect(function(hit)
				if isAttacking and not hitted then
					local hitHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
					if hitHumanoid then
						local hitRoot = hitHumanoid.Parent:FindFirstChild("HumanoidRootPart")
						if hitRoot then
							local attachment = Instance.new("Attachment")
							attachment.Parent = hitRoot

							local vectorForce = Instance.new("VectorForce")

							local X, Z = getPlayerRotation()
							local forceDirection = Vector3.new(X, 0.85, -Z)
							vectorForce.Force = forceDirection * 4500

							print(vectorForce.Force)

							vectorForce.Attachment0 = attachment
							vectorForce.ApplyAtCenterOfMass = true
							vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
							vectorForce.Parent = hitRoot

							Debris:AddItem(vectorForce, 0.5)
							print("Item1 added")
							Debris:AddItem(attachment, 0.5)
							print("Item2 added")

							print("Force applied successfully!")

							hitted = true
						else
							print("No valid HumanoidRootPart found.")
						end
					else
						print("No valid Humanoid found.")
					end
				end
			end)
		end)

		attackAnimTrack.Stopped:Wait()

		delay(0.8, function()
			debounce = false
			hitted = false
		end)
	end
end)

UIS.InputEnded:Connect(function(input)
	isAttacking = false
end)

Here is a screenshot of pushing other players in the game (it says success but nothing happens):

And a screenshot where I am attacking an NPC (everything is working):

Screenshot 2024-06-12 195339

  1. What solutions have you tried so far?
  • I have checked the Developer Hub for similar issues and solutions.
  • I have tried different methods to detect players and apply force, but none seem to work.

Thank you in advance for your help!

Also I am wondering if someone will ever answer lol