Any ideas how i could make the hitbox move with the player (welding, movescript etc)

So… making a asym game inspired by Sonic.exe TD. Making good progress but i need help with making the hitbox move with the player. Tried welding it to the player and tried making a new character though both things wouldn’t work. Any other ideas how i could do this? Thank you for your answer(s).

Hitbox Script:

local hitbox = script.Parent
local touched = false
local hitsound = hitbox.Sound
local breaksound = hitbox.BoneBreaking
local bonebroken = false
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.CR
local Teams = game.Teams
local enabledamage = false
local Attack = RS.Attack
local soundservice = game.SoundService
local attacksounds = soundservice.AttackSounds
local Tribute = attacksounds.Tribute
local Attack2 = Tribute.Attack2
local Players = game:GetService("Players")
local Attack1 = Tribute.Attack1


hitbox.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	if player and player.Team then
		local targetTeam = Teams["Survivors"]
		if player.Team ==targetTeam then
			local character = hit.Parent
			if enabledamage == true then
				if hit.Parent:FindFirstChild("Humanoid") then
					if touched == false then
						touched = true
						if hit.Name == "Head" then
							local player = game.Players:GetPlayerFromCharacter(character)
							if player then
								Remote:FireClient(player)
							end
						end
						hitsound:Play()
						print("ouch")
						if hit.Parent.Humanoid.Health > 10 then
							hit.Parent.Humanoid:TakeDamage(15)
						else
							hit.Parent.Humanoid.Health = 0.1
						end
						if hit.Parent.Humanoid.Health < 51 then
							if bonebroken == false then
								breaksound:Play()
							end
						end
						if hit.Parent.Humanoid.Health < 51 then
							bonebroken = true
						else
							bonebroken = false
						end 
						wait(2)
						touched = false
					end
				end
			end
		else
			return
		end
	end
end)


Attack.OnServerEvent:Connect(function(player)
	enabledamage = true
	hitbox.Transparency = 0
	Attack1.Parent = hitbox
	Attack2.Parent = hitbox
	Attack1:Play()
	Attack2:Play()
	print(enabledamage)
	wait(1)
	enabledamage = false
	print(enabledamage)
	hitbox.Transparency = 1
end)

Picture of the hitbox:

When welding, you need to make sure the part being welded is unanchored.
Additionally for a hitbox if you haven’t already, make sure it is CanCollide false

You can do it in a script when created, by doing this:

local function Weld(RootPart:BasePart, WeldPart:BasePart): WeldConstraint
    WeldPart.Anchored = false

    local WeldConstraint = Instance.new("WeldConstraint")
    WeldConstraint.Part0 = RootPart
    WeldConstraint.Part1 = WeldPart
    WeldConstraint.Parent = RootPart
    
    return WeldConstraint
end
2 Likes

So… got the script to work. Thank you for your help

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