How to make a raycast hitbox?

First and foremost, I’d like to address that I’m not making a hitbox for a weapon or item that gets triggered when it hits a player. Quite the opposite, actually. Im trying to make a hitbox similar to minecraft (image ref below), where a box is parented to each player, so that its position corresponds with that of the player. So when raycasting, I can just check if it hits the hitbox instead of the player’s body.

Image referance

I also want to make sure they can’t be exploited, so maybe create it from the server? If anyone cud pitch some ideas or advice, it wud b greatly appreciated.

3 Likes
local Players = game:GetService('Players')

Players.PlayerAdded:Connect(function(Player)
   Player.CharacterAdded:Connect(function(Character)
      local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
      local Part = Instance.new('Part')
      Part.Name = 'Hurtbox'
      Part.Size = Vector3.new(3.5,5,2) -- You may change this
      Part.CanCollide = false
      Part.Transparency = 0.5 -- Make transparent if you need to
      Part.CFrame = HumanoidRootPart.CFrame -- You may experiment with this because it can be placed wrong
      local Weld = Instance.new('WeldConstraint')
      Weld.P0 = Part
      Weld.P1 = HumanoidRootPart
      Part.Parent = Character
      Weld.Parent = Part
   end)
end)

After that you may try to do a whitelisted raycast (whitelist = hurtbox) and… i guess it will work.

2 Likes

Is it exploitable? If yes, how do i prevent it?

I dont think so. It’s serversided, so i guess its fine. You can only delete part for yourself using exploit, it won’t affect the actual raycast, unless it is on clientside.

2 Likes

Yes, it is exploitable. As hackers have full access to their character they can just remove the Hitbox and they will be practically unkillable

Well that can be fixed just reparenting the hurtbox.

They have access to their character but not 100%, they can’t delete parts, just make sure the hitbox was made on the server.

Yes I thought of tht, that’s why i made this post basically, but if u parent it to the plr, is it still exploitable? If yes, wts the best idea to solve this?

Its not exploitable if you parent it to player.

2 Likes

They can delete parts, I tried it with my own game and alt when I delete some part of my body it dissapeared for all

Those are body parts, any part added by the server can’t be deleted like that.

4 Likes