Why isn't the hitbox not sticking to the torso

Hello Developers.

I been trying to work on a hitbox but trying to get the hitbox welded to the characters torso isn’t working and I don’t know why.

local Box = Instance.new("Part")

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local HitBox = Box:Clone()
		Box.Parent = Character
		Box.CFrame = Character.Torso.CFrame
		local Motor = Instance.new("Motor6D",Character.Torso)
		Motor.C0 = Character.Torso.CFrame
		Motor.C1 = HitBox.CFrame
	end)
end)

What exactly isn’t working? I don’t understand what you meant it isn’t working.

Like when I press play and spawn in the part isn’t welded to me or connected to me. When I move it just stays in place

What is the part variable for?

EDIT: I understood later on, sorry for this extra reply.

  • Create a part and size it and parent it to ReplicatedStorage.
  • Then create a variable of cloning that part to the Character.
  • After that just do everything what you just did.

Another way I seen people do it is they put the part in the script then use a weld to connect it

1 Like

I think doing this instead is better.

  • Create a new RemoteEvent and name it “ActivePlayerRE” inside of ReplicatedStorage.
  • Create a LocalScript inside of the PlayButton.
  • Type in the following stuff.
local ActivePlayerRE = game.ReplicatedStorage:WaitForChild("ActivePlayerRE")

script.Parent.MouseButton1Click:Connect(function()
    ActivePlayerRE:FireServer()
    print("ActivePlayerRE has been fired!")
end)
  • Now create a new ServerScript inside of the ServerScriptService.
  • Type in the following stuff.
local ActivePlayerRE = game.ReplicatedStorage:WaitForChild("ActivePlayerRE")
local hitbox = gamr.ReplicatedStorage.Hitbox:Clone()

ActivePlayerRE.OnServerEvent:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()

    hitbox.Parent = char
    hitbox.CFrame = char.Torso.CFrame
    local motor = Instance.new("Motor6D", char.Torso)
    motor.C0 = char.Torso.CFrame
    motor.C1 = hitbox.CFrame
end)

And hopefully that helped. I’m not totally sure if it will work or not because I’m not in studio so. You can try and reply back if it worked or not! Glad to help.

EDIT: I might be wrong somewhere in the script. I’ll try to find it.

1 Like

Local script inside the playbutton?

Yep. As we fire the RemoteEvent when we click it.

If it doesn’t work you should use welds then.

I am mad confused I never heard anybody use the term “PlayButton”

I believe you may be running the script before the character is entirely loaded in

First off, you’re setting Box.Parent instead of the cloned HitBox.Parent. Secondly, you would need to set the Part0 of the motor to Torso and Part1 of the motor to the HitBox

local Box = Instance.new("Part")

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local HitBox = Box:Clone()
		HitBox.Parent = Character
		HitBox.CFrame = Character.Torso.CFrame
		local Motor = Instance.new("Motor6D",Character.Torso)
		Motor.Part0 = Character.Torso
		Motor.Part1 = HitBox
	end)
end)

image

2 Likes

It’s only the name of the Gui before when you said PlayButton

He didn’t mention ‘PlayButton’ anywhere?

It’s good and simple. Easy to understand and nothing too much. Really good example.

You cloned the box and called it HitBox but parented the Box to character, change box.Parent to hitbox.Parent same with box.CFrame