Need Help with positioning part

Does anyone know how to positon the part like that like on the photo with this script

-- Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = script.Parent.RemoteEvent

-- Damage amount
local DAMAGE_AMOUNT = 30

-- Knockback strength
local KNOCKBACK_STRENGTH = 50 -- Very high strength for extreme knockback

-- Ragdoll and stun duration
local RAGDOLL_DURATION = 2
local STUN_DURATION = 2

local HITBOX_OFFSET = 3 -- Offset for hitbox position in front of player

-- Animation asset ID
local ANIMATION_ID = "rbxassetid://112823732160036"

-- Function to handle RemoteEvent
local function onRemoteEventFired(player)
	-- Create a new part (hitbox)
	wait(0.5)
	local newPart = Instance.new("Part")
	newPart.Size = Vector3.new(17, 2.605, 2.647) -- Change size as needed
	newPart.Transparency = 0
	newPart.CanCollide = false
	newPart.Parent = workspace

	-- Get the player's humanoid root part
	local humanoidRootPart = player.Character.HumanoidRootPart
	local lookVector = humanoidRootPart.CFrame.LookVector

	-- Set position in front of the player with the desired orientation
	newPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, math.rad(90), 0) * CFrame.new(0, 0, -HITBOX_OFFSET)

	-- Weld the hitbox to the player's HumanoidRootPart
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = humanoidRootPart
	weld.Part1 = newPart
	weld.Parent = newPart

	-- Debounce table to prevent double damage
	local touchedPlayers = {}

	-- Function to deal damage, apply knockback, play animation, and apply stun when hitbox touches
	local function onTouch(otherPart)
		local character = otherPart.Parent
		local humanoid = character:FindFirstChildOfClass("Humanoid")

		if humanoid and character ~= player.Character then
			if not touchedPlayers[character] then
				touchedPlayers[character] = true
				humanoid:TakeDamage(DAMAGE_AMOUNT)

				-- Apply knockback
				local rootPart = character:FindFirstChild("HumanoidRootPart")
				if rootPart then
					local direction = (rootPart.Position - newPart.Position).unit
					local bodyVelocity = Instance.new("BodyVelocity")
					bodyVelocity.Velocity = direction * KNOCKBACK_STRENGTH
					bodyVelocity.P = 100000 -- Extremely high pressure for instant knockback
					bodyVelocity.MaxForce = Vector3.new(100000, 100000, 100000) -- Ensure the force is applied
					bodyVelocity.Parent = rootPart

					-- Remove the BodyVelocity after a short period to stop the knockback effect
					game:GetService("Debris"):AddItem(bodyVelocity, 0.1)
				end

				-- Trigger ragdoll effect
				humanoid.PlatformStand = true -- Disable the humanoid's control to simulate ragdoll

				-- Play hit animation on the target for 1 second in a loop
				local animator = humanoid:FindFirstChildOfClass("Animator")
				if animator then
					local hitAnimation = Instance.new("Animation")
					hitAnimation.AnimationId = ANIMATION_ID
					local animationTrack = animator:LoadAnimation(hitAnimation)
					animationTrack.Looped = true -- Set the animation to loop
					animationTrack:Play()

					-- Let the animation loop for 1 second
					wait(1)

					-- Stop the animation after 1 second
					animationTrack:Stop()
				end

				-- Apply stun effect after the animation
				humanoid.WalkSpeed = 0
				humanoid.JumpPower = 0

				-- Restore normal state after ragdoll and stun duration
				wait(STUN_DURATION)
				humanoid.WalkSpeed = 16 -- Reset to default WalkSpeed
				humanoid.JumpPower = 50 -- Reset to default JumpPower

				humanoid.PlatformStand = false
			end
		end
	end

	-- Connect the touch event
	newPart.Touched:Connect(onTouch)

	-- Destroy the part after 1 second
	game:GetService("Debris"):AddItem(newPart, 1)
end

-- Connect the function to the RemoteEvent
RemoteEvent.OnServerEvent:Connect(onRemoteEventFired)

newPart.CFrame = humanoidRootPart.CFrame + (humanoidRootPart.CFrame.LookVector * HITBOX_OFFSET)

1 Like

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