Humanoid is not a valid member of Workspace "Workspace"

It still works but I want to remove the error (“Humanoid is not a valid member of Workspace “Workspace””)

Remote.OnServerEvent:Connect(function(e,Direction,Origin)
	Sound:Play()
	local Damage = math.random(10,30)
	local Head = math.random(1,2)
	local Damage2 = math.random(88,100)
	local Paramas = RaycastParams.new()
	Paramas.FilterType = Enum.RaycastFilterType.Blacklist
	Paramas.FilterDescendantsInstances = {e.Character}
	
	
	local Hit = workspace:Raycast(Origin,Direction,Paramas)
	
	if Hit.Instance then
		print(Hit.Instance.Name)
	if Hit and Hit.Instance and Hit.Instance.Name == "Head" and Head == 1 then
		Hit.Instance.Parent.Humanoid.Health = Hit.Instance.Parent.Humanoid.Health-100
    
		local Clone = Hit.Instance.Parent.Head:Clone()
		Clone.Parent = Hit.Instance.Parent
		Clone.Anchored = false
		Clone.Name = "LimbHead"
		for _,v in pairs(Hit.Instance.Parent.LimbHead:GetDescendants()) do
			if v.ClassName == "Motor6D" then
				v:Destroy()
			end
	
		end
		local BodyV = Instance.new("BodyVelocity",Hit.Instance.Parent.LimbHead)
		BodyV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		BodyV.Velocity = e.Character.HumanoidRootPart.CFrame.LookVector*23+Vector3.new(0,5,0)
		game.Debris:AddItem(BodyV,.1)
		Hit.Instance:Destroy()
	elseif Hit and  Hit.Instance and Hit.Instance.Name == "Head" and Head == 2 then
		Hit.Instance.Parent.Humanoid.Health = Hit.Instance.Parent.Humanoid.Health-Damage2
	elseif Hit and Hit.Instance and  Hit.Instance.Name ~= "Head" and Hit.Instance.Parent.Humanoid then
		Hit.Instance.Parent.Humanoid.Health = Hit.Instance.Parent.Humanoid.Health-Damage
		
     
       end
	end
end)
1 Like
Remote.OnServerEvent:Connect(function(e,Direction,Origin)
	Sound:Play()
	local Damage = math.random(10,30)
	local Head = math.random(1,2)
	local Damage2 = math.random(88,100)
	local Paramas = RaycastParams.new()
	Paramas.FilterType = Enum.RaycastFilterType.Blacklist
	Paramas.FilterDescendantsInstances = {e.Character}
	
    local Hit = workspace:Raycast(Origin, Direction, Paramas)

    if Hit and Hit.Instance and Hit.Instance.Parent then
        print(Hit.Instance.Name)

        local HeadCheck = Hit.Instance.Name == "Head"
        local HumCheck = Hit.Instance.Parent:FindFirstChild("Humanoid")

        if HumCheck and HeadCheck then
           
            if Head == 1 then
                Hit.Instance.Parent.Humanoid.Health = Hit.Instance.Parent.Humanoid.Health-100
    
		        local Clone = Hit.Instance.Parent.Head:Clone()
		        Clone.Parent = Hit.Instance.Parent
		        Clone.Anchored = false
		        Clone.Name = "LimbHead"

	        	for _,v in pairs(Clone:GetDescendants()) do
	    	    	if v.ClassName == "Motor6D" then
				        v:Destroy()
			        end
		        end

            elseif Head == 2 then
                HumCheck.Health -= Damage2
            else
                HumCheck.Health -= Damage
            end
        end
    end
end)

That’s a lot of things you’re indexing, I’d recommend using variables to shorten your script a bit easier

1 Like