Hats not working with damage script from raycasting

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? A script where if you click you can damage yourself.

  2. What is the issue? hats not working with the script. But I think it also does the same thing if its a model.

Example (Humanoid is not a valid member of Accessory "Workspace.irlkalei.Meshes/smugAccessory"  -  Client - LocalScript:20) I want it to damage them even if they have a hat to block it.

local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local item = nil

local function MouseRayCast()
	local mousepos = UIS:GetMouseLocation()
	local mouseray = cam:ViewportPointToRay(mousepos.X, mousepos.Y)
	local rcr = workspace:Raycast(mouseray.Origin, mouseray.Direction*1000)
	return rcr
end

UIS.InputBegan:Connect(function(input, processed)
	if processed then
		return
	end
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local result = MouseRayCast()
		if result and result.Instance then
			result.Instance.Parent.Humanoid.Health = result.Instance.Parent.Humanoid.Health - 25
		end
	end
end)

RunService.RenderStepped:Connect(function()
	local result = MouseRayCast()
	if result and result.Instance then
		item = result.Instance
	end
end)
  1. What solutions have you tried so far? Ai, rescripting the line.

The 1st and 2nd lines of code isnt suppose to be there so start at “local RunService = game:GetService(“RunService”)” when you read please.

You need to check if there’s a humanoid in the hit’s parent. If there is, then it’s a limb and not an accesory, and it won’t error.

But the model parent is the player, then its just player to humanoid.

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